[ACCEPTED]-Xpath: how to select an option based on its text not value property?-xpath
Accepted answer
To select by text value you can use text()
function. And 8 normalize spaces is required, because they 7 are not removed by default. Here is an example:
select/option[normalize-space(text())="Grass"]
@value
- value 6 of "value" attribute
@val
- value of 5 "val" attribute
normalize-space()
- function returns 4 the argument string with whitespace normalized 3 by stripping leading and trailing whitespace 2 and replacing sequences of whitespace characters 1 by a single space
Well, if whitespace isn't an issue:
/select/option[.='Grass']
I'd need 2 to check re whitespace, though. You could 1 always normalize:
/select/option[normalize-space(.)='Grass']
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.