I have a variable that is a By class. I wish to call FindElements to return the corresponding element as well as all of the parent elements of this
I created WebElement extension, I hope useful.
public static IWebElement GetElementParentByClass(this IWebElement element, string ClassName)
{
try
{
IWebElement parent = element;
do
{
parent = parent.FindElement(By.XPath("./parent::*")); //parent relative to current element
} while (!parent.GetAttribute("class").Equals(ClassName));
return parent;
}
catch (Exception ex)
{
return null;
}
}