Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath - How to select parent based on attribute of child?

How do you select a parent based on the attribute of a child?

I want to select a div:

//*[@id='outer']/div/div/div/div

that has a child with the 'a href' attribute equal to 'www.blah.com':

//*[@id='outer']/div/div/div/div/a[@href='www.blah.com']
like image 814
Chris Avatar asked Nov 01 '09 12:11

Chris


2 Answers

The basic fact you need is that predicates can be nested:-

//*[@id='outer']/div/div/div/div[a[@href='www.blah.com']]
like image 193
AnthonyWJones Avatar answered Oct 22 '22 04:10

AnthonyWJones


//*[@id='outer']/div/div/div/div/a[@href='www.blah.com']/../
like image 42
Faruz Avatar answered Oct 22 '22 03:10

Faruz