Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make find_by_value works with btn elements #746

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions splinter/driver/lxmldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ def find_by_tag(self, tag):
)

def find_by_value(self, value):
return self.find_by_xpath(
elem = self.find_by_xpath(
'//*[@value="%s"]' % value, original_find="value", original_selector=value
)
if elem:
return elem
return self.find_by_xpath('//*[.="%s"]' % value)

def find_by_text(self, text):
xpath_str = _concat_xpath_from_str(text)
Expand Down Expand Up @@ -412,7 +415,10 @@ def __getitem__(self, attr):

@property
def value(self):
return self._control.value
try:
return self._control.value
except AttributeError:
return self._control.text

@property
def checked(self):
Expand Down
5 changes: 4 additions & 1 deletion splinter/driver/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,15 @@ def find_by_tag(self, tag, wait_time=None):
)

def find_by_value(self, value, wait_time=None):
return self.find_by_xpath(
elem = self.find_by_xpath(
'//*[@value="{}"]'.format(value),
original_find="value",
original_query=value,
wait_time=wait_time,
)
if elem:
return elem
return self.find_by_xpath('//*[.="%s"]' % value)

def find_by_text(self, text=None, wait_time=None):
xpath_str = _concat_xpath_from_str(text)
Expand Down
5 changes: 4 additions & 1 deletion splinter/driver/zopetestbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ def find_by_tag(self, tag):
)

def find_by_value(self, value):
return self.find_by_xpath(
elem = self.find_by_xpath(
'//*[@value="%s"]' % value, original_find="value", original_selector=value
)
if elem:
return elem
return self.find_by_xpath('//*[.="%s"]' % value)

def find_by_text(self, text):
xpath_str = _concat_xpath_from_str(text)
Expand Down
5 changes: 5 additions & 0 deletions tests/find_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def test_finding_by_value(self):
id = self.browser.find_by_id("gender-m")
self.assertEqual(id.value, value)

def test_finding_by_value_in_btn_elements(self):
value = self.browser.find_by_value("some value").value
btn = self.browser.find_by_id("button-value")
self.assertEqual(btn.value, value)

def test_finding_by_text(self):
element = self.browser.find_by_text("Complex")
self.assertEqual(element.value, "Complex")
Expand Down
1 change: 1 addition & 0 deletions tests/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<body>
<h1 id="firstheader">Example Header</h1>
<h1 id="firstheader">Example Last Header</h1>
<button id="button-value">some value</button>
<form action="name" method="GET">
<label for="query">Query</label>
<input type="text" name="q" />
Expand Down