问题
I am planning a tool in Java which would have a drop down containing all the elements of a web page. Is there any way I can read those into a data structure?
回答1:
Yes, there is a way.
Here is some pseudo-code:
List<WebElement> el = driver.findElements(By.cssSelector("*"));
for ( WebElement e : el ) {
add(e.tagName());
}
回答2:
non-pseudo C# version of above: (although I'm just displaying the results in a console
IReadOnlyCollection el = driver.FindElements(By.CssSelector("*"));
foreach (IWebElement elm in el)
{
Console.WriteLine(elm.TagName + elm.Text);
}
来源:https://stackoverflow.com/questions/19683016/selenium-find-all-elements-of-a-web-page