Home > Blockchain >  XPATH use AND OR combination
XPATH use AND OR combination

Time:12-02

I got the following HTML code:

<div><h6>abc/h6><p>date</p></div>

I can successfully find this element with selenium based on text. Now the problem is that <h6> can contain different words like "def" OR "ghi". How can i add a OR in the following XPATH? With only AND this is working:

"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc')]]"

Now with AND & OR have tried without success

"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc') or preceding-sibling::h6[contains(text(),'def')]]"

also this without success

"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc' or 'def')]]"

CodePudding user response:

Inside of the predicate for h6, test whether it contains 'abc' or contains 'def':

//div/p[contains(text(),'date') 
  and preceding-sibling::h6[contains(text(),'abc') or contains(text(),'def')]]

CodePudding user response:

Make the <p> predicate in and with <h3> either with text abc or def as follows:

//div//p[contains(.,'date')] [//preceding-sibling::h6[contains(.,'abc')] or //preceding-sibling::h6[contains(.,'def')]]
  • Related