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')]"));
text(): A built-in method in Selenium WebDriver that is used with XPath locator to locate an element based on its exact text value.
The syntax for locating elements through XPath- Using contains() method can be written as: //<HTML tag>[contains(@attribute_name,'attribute_value')]
How will you write XPath if the tag has only text? We will start to write XPath with //, followed by input tag, then we will use the select attribute, followed by its attribute name like name, id, etc, and then we will choose a value of attribute in single quotes. Here, (1 of 1) means exact match.
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')]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With