我试图识别项目显示在优势购物页面。我使用下面的属性来标识对象。对象标识中心标识多个对象,但我的脚本返回0
imgsCnt=browser.findChildren(WebElement.class,new WebElementDescription.Builder().className("ng-scope").tagName("LI").build());
System.out.println("# ItemsPresent : : "+imgsCnt.length);WebPage网址:http://www.advantageonlineshopping.com:8080/#/category/5
我想用'li‘元素来识别可用的项目列表。
发布于 2017-08-31 08:13:01
我设法重现了这个问题。
之所以会发生这种情况,是因为在进行检查(findChildren)时,元素实际上“不在那里”。
为了获得所有元素,需要添加某种等待,以确保项目被看到。
因此,下面的代码现在已经工作了,只有5秒的睡眠时间。(Ofc应该应用另一种逻辑,这只是为了演示解决方案)。
public void test() throws Exception {
Browser browser = BrowserFactory.launch(BrowserType.CHROME);
browser.navigate("http://www.advantageonlineshopping.com:8080/#/category/Mice/5");
Thread.sleep(5000); // this was the key difference between cnt 0 and cnt 11
WebElement[] imgsCnt = browser.findChildren(WebElement.class, new WebElementDescription.Builder()
.className("ng-scope")
.tagName("LI").build());
System.out.println("# ItemsPresent : : "+imgsCnt.length);
browser.close();
}https://stackoverflow.com/questions/42563440
复制相似问题