Reputation: 273
I know that you can get a parent element when using Selenium for Java and XPath like this:
WebElement parent = child.findElement(By.xpath(".."));
But how do I get the next sibling of an element, what do I need to put between the parentheses instead of two dots as in the case above?
Upvotes: 18
Views: 39390
Reputation: 81
WebElement parent = child.findElement(By.xpath("following-sibling::*[X]"));
X will be the Xth sibling of that element.
Upvotes: 8
Reputation: 89285
Use following-sibling
axis :
WebElement followingSibling = child.findElement(By.xpath("following-sibling::*"));
List of available axes by MDN, for further reference : Mozilla Developer Network : Axes
Upvotes: 43