Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am new to XPath, trying to get the 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 on 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.

1 Answer

0 votes
by (62.9k points)

I am using get_attribute("value") method and it works decently:

 for i in browser.find_elements_by_xpath("//*[@type='submit']"):

    print i.get_attribute("value")

I hope this helps!

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing certification!

Browse Categories

...