Python Selenium: Find object attributes using xpath

0
0

I am new to xpath, trying to get value of the “value” using xpath:

<input type="submit" value="  Search  " class="long searchButton" style="width:190px !important;">

while it is easy to find element by "type="submit" like:

browser.find_elements_by_xpath("//*[@type='submit']")

I haven’t been able to figure out how to get the values I need, as:

browser.find_elements_by_xpath("//*[@type='submit']/@value")

somewhat expectedly gives an error:

expression "//*[@type=\'submit\']/@value" is: [object Attr]. It should be an element

Any ideas how to solve this?

EDIT:
The xpath is correct, but it “returns” an obj attribute and as it is not an element, it is not allowed. I can’t find a method like get_attr_by_xpath(), or anything similar.

  • You must to post comments
0
0

I finally used get_attribute("value") as:

for i in browser.find_elements_by_xpath("//*[@type='submit']"):
print i.get_attribute("value")
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website