How to get all descendants of an element using webdriver?

Code Enthusiastic picture Code Enthusiastic · Dec 27, 2012 · Viewed 83.8k times · Source

There is this element which has child elements, those child elements again have child elements and so on. I would like to get all elements that are descendants of the element. Thanks.

Answer

Igor Khrol picture Igor Khrol · Dec 27, 2012

Try this one:

(Java)

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

(C#)

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