Adnan Ghaffar
Adnan Ghaffar

Reputation: 1423

Selenium Webdriver - XPath: How to use 'and' 'Or' in xpath

I want to create XPath as //a[class='btn btn-invisible btn-link routeLink'] and //a[data-route='#Leads'].

Other example: //div[@class='btn-group'] and //a[@text()='Leads']

HTML:

<div class="btn-group" style="display: none;">
<a class="btn btn-invisible btn-link routeLink" data-route="#Leads" href="#Leads">Leads</a>

Upvotes: 1

Views: 2113

Answers (2)

Anirudh
Anirudh

Reputation: 2326

I think below is what you need:

1) //a[@class='btn btn-invisible btn-link routeLink'][@data-route='#Leads']


2) //div[@class='btn-group'][text()='Leads']

and if you really need to use 'and' then niharika_neo's suggestion should work too.

Upvotes: 1

niharika_neo
niharika_neo

Reputation: 8531

//a[@class='btn btn-invisble' and data-route='#Leads']

In the second example: Do you want a div or do you want an anchor? Shouldn't those be different locators?

You can or them as such using a pipe: //div[@class='x']|//a[@text='aa'].

Upvotes: 2

Related Questions