【问题标题】:LeanFt WebClass IdentificationLeanFt WebClass 识别
【发布时间】:2017-03-02 18:44:41
【问题描述】:

我正在尝试识别 Advantage 购物页面中显示的商品。我正在使用以下属性来识别对象。对象识别中心识别多个对象,但我的脚本返回 0

imgsCnt=browser.findChildren(WebElement.class,new WebElementDescription.Builder().className("ng-scope").tagName("LI").build());
System.out.println("# ItemsPresent : : "+imgsCnt.length);

网页网址:http://www.advantageonlineshopping.com:8080/#/category/5

我想使用 'li' 元素识别可用项目列表。

【问题讨论】:

    标签: leanft


    【解决方案1】:

    我设法重现了这个问题。

    发生这种情况的原因是,在进行检查 (findChildren) 时元素确实“不存在”。

    为了获取所有元素,需要添加某种等待,以确保看到项目。

    因此,以下代码现在可以正常工作,睡眠时间为 5 秒。 (应该应用另一个逻辑,这只是为了演示解决方案。

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-01
      • 2020-11-11
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      相关资源
      最近更新 更多