I'm trying to create a method that given a WebElement finds and returns the very next element. I have found a lot of examples for what should work using XPath with "following" or "following-sibling" but I can't get it to work. For the purpose of the question here I will show the html, but the element types are irrelevant for what I need as I want a generic method that given any element of any type (a/ul/div/whatever) it will return the next sibling regardless of type.
<a id="blah" href="#" class="stuff">"My Label"</a>
<ul class="some-class">
<li>...</li>
<li>...</li>
</ul>
My buggy debugging code:
IWebElement element = driver.FindElement(By.Id("blah"));
IWebElement nextElement = element.FindElement(By.XPath("//following-sibling::ul[@class='some-class']"));
I suspect my xpath syntax is wrong... and I am frankly clueless. Does the "//" mean relative to element or to the DOM itself? Is there a way of doing this without knowing what the tag of the next element is? I would like to just get the next element no matter what type it is. I'd just like to figure out the simplest and most generic way to do this. What I would like to have:
public IWebElement NextSibling(IWebElement element)
{
IWebElement nextSibling = element.FindElement(By.?("magical string to find next sibling"));
return nextSibling;
}
...which is exactly what you can already do in javascript with element.nextSibling()