XPath Selenium VBA XPath Selenium VBA selenium selenium

XPath Selenium VBA


So you need to break your problem into two parts

(element we need to select)[condition that element has to match]

Let's solve them one by one

element we need to select

So we know that the element will have a class searchedDivClass. So this one is quite simple and below should work

//div[contains(@class,'searchedDivClass')]

condition that element has to match

The first condition is that that there should be a following div tag (or basically a sibling.

following-sibling::div[1]

Now next condition we want to add on this sibling, which is that this sibling should have a child which has text some text. So we update our xpath with another condition

following-sibling::div[1][.//*[contains(text(),'some text')]]

Notice that i used a .// and not // because .// will take from current nodes child, while the // you use means anywhere in the document.

So our final XPATH will be

//div[@class='searchedDivClass'][following-sibling::div[1][.//*[contains(text(),'some text')]]]