java 是否可以使用 WebDriver 在网页上获取所有 WebElements
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12061169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to get ALL WebElements on a web page using WebDriver
提问by kamal
Something like:
就像是:
WebElement inputs = driver.findElement(By.tagName("input"));
or
或者
List<WebElement> links = driver.findElementsBy(By.tagName("a"));
What i wanted was a name/value pair like structure which gives me tagName vs Quantity My Objective is to have a list of these Elements and make a Series of tests associated with them, since different users would have their own unique set of these Elements per page. I hope i got my message across.
我想要的是一个像结构一样的名称/值对,它给我 tagName vs Quantity 我的目标是拥有这些元素的列表并进行一系列与它们相关的测试,因为不同的用户将拥有自己独特的这些元素集页。我希望我能传达我的信息。
回答by James
You could do something like:
你可以这样做:
List<WebElement> allElements = driver.findElements(By.xpath("//*"));
or
或者
List<WebElement> allElements = driver.findElements(By.cssSelector("*"));
Then just sort the list as needed using getTagName or other functions.
然后只需使用 getTagName 或其他函数根据需要对列表进行排序。
回答by kamal
This repolooks promising, as page object generation tool
这个repo看起来很有前途,作为页面对象生成工具
look at Paul Grandjean Prototype Tool for Configurable Selenium Code Generation
看看Paul Grandjean Prototype Tool for Configurable Selenium Code Generation