Reputation: 35813
I have a page with an element:
<input id="foo"></input>
which (via Javascript) has had its value
set to "bar".
If I use the following XPath statement (with Python/Selenium):
self.browser.find_elements_by_xpath("//input[@id='foo']")
it returns my element, and I can even do:
self.browser.find_elements_by_xpath("//input[@id='foo']")[0].get_attribute("value")
and get u"bar"
back. However, if I try to do:
self.browser.find_elements_by_xpath("//input[@value='bar']")
or even just:
self.browser.find_elements_by_xpath("//input[@value]")
my element doesn't get returned.
The only way this makes sense to me is if my Javascript code is setting the "value" property, not the "value" attribute (and when I look at the element in the Firefox inspector it doesn't show a "value" attribute, which reinforces this theory).
So, my question is, how do I select elements with a "value" property instead?
Upvotes: 3
Views: 2746
Reputation: 1680
As you've apparently figured out, you're not really interested in the [@value] which is the 'value' attribute on the DOM object. Instead you're trying to find the value of the "foo" property on the JavaScript object.
Normally properties for JavaScript objects aren't exposed on the DOM. You'd need to query down into the JavaScript itself to look at those objects and their properties. You can do that via the JavaScript executor. I've not used the Python bindings for WebDriver, so the exact syntax/approach may vary a bit--but the approach is generally the same.
Upvotes: 2