2

我正在创建一个自动化框架,我需要从元素中获取值并将其与我事先收集的值相匹配。现在,问题是,在页面加载后会更新 div 值,因此即使在添加隐式等待/流利等待/Thread.sleep 之后,代码也不起作用。但是当我调试代码时,代码可以正常工作而无需进行任何更改。我不确定必须做些什么。

由于我是新用户,因此我无法在此问题中添加图像,但初始“总计:值”为“总计:0”并且需要一些时间来填充因此它会更改,但由于预先加载了页面超时不起作用。

请提出一些建议。

        String sID = oIPops.getLocator("<value from properties file>");

    /*
    WebDriverWait wait = new WebDriverWait(driver,40);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(sID)));
    */

    try {
        Thread.sleep(10);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       

    String tValue = driver.findElement(By.id(sID)).getText();
    System.out.println(""+tValue);  // it will print Total : <populated value>

   // Extracting the number from the string to match with data I have beforehand
    char num = tValue.charAt(7);
    String character = "+" + num;
    Integer newNum = new Integer(character);
    if (value == newNum)
    {
        logger.info("Sum of Situations on Cluster "+title+ " matches with the total value from situation table");
    }
    else
    {
        logger.error("Sum of Situations on Cluster "+title+ " does not match with the total value from situation table");
    }
4

1 回答 1

0

It's easy. All you do is handle the element exception using the .ignoring method of the FluentWait class and then do a retry (within a finite loop) to re-find the element and try again. It might be easier to do without using FluentWait and then just handle the exception the regular Java way.

于 2013-09-05T20:19:52.873 回答