I would like to find the Xpath, where the Text contains two names. I want my xpath to identify any one of the conditions below.


//div[text()='USER NAME' OR text()='USER ID']


//div[text()='USER NAME' | text()='USER ID']

Can i use like above, Actually both are not working. Please help me with identification.

4 Answers 4


XPath definitely supports OR expressions. It is also case-sensitive. Use text() rather than TEXT() and or rather than OR. You didn't show us the HTML fragment, so I can't tell whether you really want 'USER NAME' or 'user name' or 'User name'. You will have to figure that out for yourself.

Try this:

 //div[text()='USER NAME' or text()='USER ID']

When you run into problems like this, go the web page you are interested in and open up the browser debugger. You can probably experiment with XPath expressions there. In the Chrome debugger, you can use

$x(expression goes here),


$x("//div[text()='USER NAME' or text()='USER ID']"

You can use the contains in the xpath with the common String is USER
like this


Here's the link to know more-http://automationtricks.blogspot.in/search/label/xpath


I would suggest the approach you are taking may need reevaluation.

A test needs to be repeatable. You should therefore be able to replicate the conditions where the ID is returned and also when the Name is.

As such, I would recommend that instead of using an OR, you should instead have 2 separate tests that assert each condition independently.


Definitely you can use OR condition such as //a[text()='Or Conditions in ' | text()='Xpath'] but as I understand your requirements, I would suggest using contains.

Your second xpath should work. Please check your text's case. Xpath is case sensitive so or conditions in is not the same as Or Conditions in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.