What is the correct format to retrieve an attribute from an element of some id using selenium.getAttribute ()?

I tried to track down the appropriate syntax to retrieve the attribute using selenium.getAttribute (someXPath) and although I came across many examples, nothing seems to work. From what I can tell the standard xpath syntax like:

//*[@id='someID']

      

does not work. What is the correct format to extract an attribute from an element of some id?

+1


a source to share


1 answer


So it seems that this format is almost right. The correct line would be

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

      

Another solution is to use



"someId@someAttribute"

      

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

It also appears that when an element has no attributes at all, the "attributeValue is null" error message instead of the usual "Element / attribute not found" error message.

+2


a source







All Articles