Reputation:
There is an anchor tag, whose value can be changed by the user. Now, i want to write an Xpath query that searches for multiple link text names in one statement itself.
<a href="#login" class="fancybox" xpath="1">Signin</a>
now, link text value can be changed by user profile. for eg, "Login", "Log-in", "Click here to login" or "Login now"
If i write xpath:-
//a[contains(text(),'Login') or contains(text(),'Log-in') or contains(text(),'Login now') or contains(text(),'click here to Login')]
Then it fails. I need to click this element using Selenium.
Please help.
Upvotes: 2
Views: 801
Reputation: 111541
Important notes:
contains()
when you need substring testing. See What does contains() do in XPath?Signin
, but your XPath does not.click here to Login
is not the same as Click here to Login
.If you're certain there are no whitespace variations:
//a[.='Login' or .='Log-in' or .='Click here to login' or .='Login now']
Otherwise:
//a[ normalize-space()='Login"
or normalize-space()='Log-in'
or normalize-space()='Click here to login'
or normalize-space()='Login now']
//a[normalize-space()=('Login','Log-in','Click here to login','Login now')]
Upvotes: 5
Reputation: 22177
XPath is based on sequences. So you can use a comma separated list, i.e. sequence, to imitate logical OR conditions.
XPath
//a[text()=("Login","Log-in","Click here to login")]
Upvotes: 1