How to get all descendants of an element using webdriver? How to get all descendants of an element using webdriver? java java

How to get all descendants of an element using webdriver?


Try this one:

(Java)

List<WebElement> childs = rootWebElement.findElements(By.xpath(".//*"));

(C#)

IReadOnlyList<IWebElement> childs = rootWebElement.FindElements(By.XPath(".//*"));


Try this one

List<WebElement> allDescendantsChilds = rootWebElement.findElements(By.xpath("//tr[@class='parent']//*"));

The above thing will gives you all descendant child elements (not only immediate child) of parent tr


Try this one:

List<WebElement> childs = rootWebElement.findElements(By.tagName(".//*"));