silhouette hustler
silhouette hustler

Reputation: 1763

Find an element by Xpath which contains text

This works fine if I search for a single string:

var element = Driver.FindElement(By.XPath("//a[contains(text(), 'About us')]"));

But could I have an or statement like in the example below?

var element = Driver.FindElement(By.XPath("//a[contains(text(), 'About us' or 'about us')]")); 

Upvotes: 8

Views: 45419

Answers (2)

Vishal Jagtap
Vishal Jagtap

Reputation: 896

Below satisfies your requirement:

//a[contains(., 'About us') or contains(., 'about us')] 

Refer:- https://sqa.stackexchange.com/questions/10342/how-to-find-element-using-contains-in-xpath for more details.

Upvotes: 1

splash58
splash58

Reputation: 26153

say or between two calls of contains function

//a[contains(text(), 'About us') or contains(text(), 'about us')]

or use translate function to make xpath case insensitive

//a[contains(translate(text(), 'ABOUTS', 'abouts'), 'about us')]

Upvotes: 13

Related Questions