Gyan Ranx
Gyan Ranx

Reputation: 15

Selenium - Select element based on multiple attributes via Xpath

I did a google Search for the word 'Apple' using Selenium.

Using the below xpath i am trying to get hyperlinks only if the search results that has the word 'Cupertino' in it. But it does return nothing!

//a[contains(.,'Apple') and //span/em[contains(.,'Cupertino')]]

Google Search Results Screenshot:

enter image description here

Can someone help me out with correcting the Xpath i used?

Upvotes: 1

Views: 403

Answers (1)

Andersson
Andersson

Reputation: 52665

Try below XPath

//h3[contains(.,'Apple') and following-sibling::div[contains(.,'Cupertino')]]/a

Upvotes: 1

Related Questions