How to check if div contains text (XPath)

Viewed 26

I use https://autorefresh.io/expressions/ chrome extension for page refreshing. The next level for me is checking if a specific page part contains the predefined text. This extension supports XPath. I was trying to use //*[contains(text(),"Brak towaru")]. It worked until I put this cell "address" instead of *.

/html/body[@class='b--desktop breakpoint-xl']/div[@class='body-inner']/
section[@class='pt-2']/div[@id='main']/div[@class='shop']/
div[@class='row mt-4 justify-content-center'][1]/div[@class='col-4 col-md-2 pt-3 text-center']

I was trying to insert this "address" in many ways... No success.

Any hints?

screenshot of XPath extension

2 Answers

Instead of using contains(text()) try using contains(.,). This will check for text content in the element itself and in it's child nodes.
So, instead of

//*[contains(text(),"Brak towaru")]

Try using

//*[contains(.,"Brak towaru")]

And in case this is a div element use

//div[contains(.,"Brak towaru")]

Thank you very much. Works :) //*[@id="main"]/div/div[3]/div[3][contains(.,"Brak towaru")]

Related