XPath for element by attribute value in Selenium?

Viewed 328

For the following HTML:

enter image description here

Why does the following XPath doesn't work:

//option[value='0']

Is it related to value or to option element?

3 Answers

Change

//option[value='0']

to

//option[@value='0']

because value is an attribute, not an element.

Your current xpath is searching for an option element with a child element value which in turn has contents 0. What you actually want to find is an option element with an attribute value with value 0:

//option[@value='0']
Related