Selenium - Find all elements of a web page

倾然丶 夕夏残阳落幕 提交于 2021-02-18 09:32:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!