Find element by xpath, called on element - does not work with relative xpath selectors (e.g. "..", "./following-sibling::*")

Given

element = driver.findElement(By.xpath("//*[@name='foo'"));

then the following code will fail with NoSuchElementException:

element.findElement(By.xpath(".."))  

or

element.findElement(By.xpath("./following-sibling::*"))  

While both parent and sibling elements, relatively to the element with name=foo - exist

Why?

p.s.
I face the issue at least on IOS device, appium 1.15.0-1, appium java client: 7.2.0

Also interesting is that

element.findElement(By.xpath("."))  

works, it finds “itself”, the same element…

this:

element.findElement(By.xpath("./*"))  

also works…

but then this:

element.findElement(By.xpath("./*/following-sibling::*"))  

does not work

1 Like