-1

我们正在使用以下代码片段以安全地传递到下一个测试步骤。

private void waitTextPresent(String toBeExpectedText) throws InterruptedException {
         for (int second = 0;; second++) {
                if (second >= 60) {
                       // not found
                }
                try {

                       if (driver.findElement(By.cssSelector("BODY")).getText()
                       .matches(toBeExpectedText))
                       break;
                } catch (Exception e) {
                }
                Thread.sleep(1000);
         }
   }

我们正在使用Selenium 2.44.0(这似乎是稳定版本)。Firefox版本是 37.0,因为 v38 和 v39 有问题,以前的版本很慢。

然而,即使这个代码片段运行太慢,测试的总时间也太长了。有没有办法以更有效的方式重写这个片段?

4

1 回答 1

2

您可以使用预期条件。

根据您的要求,只需这 1 行代码即可。

new WebDriverWait(driver,60).until(ExpectedConditions.textToBePresentInElement(element, txt));

于 2015-07-24T15:04:56.177 回答