I am trying to find an XPath query to get an ancestor of my element, which is a div with a class='row publication-detail teaser'.
What I am currently doing is the following :
element.findElements(By.xpath("//ancestor::div[@class='row publication-detail teaser']"));
The problem is, it is returning all the siblings of div[@class='row publication-detail teaser']. And I only need the one that's my elements ancestor.
What am I doing wrong?
You are almost correct, but
findElementswill give you list of elements instead usefindElementtry replacing your code like this :