如何使用webdriver获取元素的所有后代?

Cod*_*tic 40 java collections selenium webdriver

有这个元素有子元素,那些子元素又有子元素等等.我想得到作为元素后代的所有元素.谢谢.

Igo*_*rol 83

试试这个:

(JAVA)

List<WebElement> childs = rootWebElement.findElements(By.xpath(".//*"));
Run Code Online (Sandbox Code Playgroud)

(C#)

IReadOnlyList<IWebElement> childs = rootWebElement.FindElements(By.XPath(".//*"));
Run Code Online (Sandbox Code Playgroud)


San*_*rma 5

试试这个

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

上面的内容将为您提供父tr的所有后代子元素(不仅是直接子元素)