tags:

views:

226

answers:

1

I've tried tracking down the appropriate syntax to extract an attribute using selenium.getAttribute(someXPath), and while I've come across many examples, nothing seems to work. From what I can tell, standard xpath syntax, such as:

//*[@id='someID']

doesn't work. What's the correct format to extract an attribute from an element of some id?

+1  A: 

So it seems as if that format is almost correct. The correct string would be

//*[@id="someId"]@someAttribute

Another solution is to use

"someId@someAttribute"

which actually is "better" as the former can generate errors for IE.

Also, it seems that when an element contains no attributes at all, the error message is "attributeValue is null" instead of the normal "Element / attribute not found".

Tom Bennett
Not only is it better, but it is also much faster... using xpaths in selenium can be VERY slow.
Igor Brejc