运行selenium测试时,ExpectedConditions类会引发许多错误

时间:2017-02-21 12:46:31

标签: java selenium

我的测试曾经在2月20日之前运行良好。从今天上午开始,我在控制台中看到了很多错误。他们看起来像:

лют. 21, 2017 2:38:19 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.xpath: //a[@href='/#/activities']//span)
org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //a[@href='/#/activities']//span
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.1.0', revision: 'b94c902', time: '2017-02-16 12:21:31 -0800'
System info: host: 'SALSALABS5', ip: '192.168.15.114', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:41)
    at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:181)
    at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:178)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:234)
    at com.vitalii.vitaliiFramework2.helpers.Waiters.fluentWaitIgnoringNoSuchElementExceptionAndElementNotVisibleException(Waiters.java:85)
    at com.vitalii.vitaliiFramework2.pages.DashboardPage.goToActivitiesPage(DashboardPage.java:20)
    at com.vitalii.vitaliiFramework2.tests.LoginPageTestsWD.doSuccessfulLoginTest(LoginPageTestsWD.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

显然这是因为ExpectedConditions类。

Project已成功编译,我的IDE在任何类中都没有显示任何错误。该问题仅在测试运行期间观察到,并且总是导致测试在某些时候失败。

我没有更新浏览器或我的pom.xml。周末之前很好,但现在失败了。

浏览器 - FF 47.0 硒 - 3.1.0

使用ExpectedConditions类的代码示例是:

public void fluentWaitIgnoringNoSuchElementExceptionAndElementNotVisibleException(final String locator){
        long waitingTime = 30; 
        long pollingInterval = 500;
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(waitingTime, TimeUnit.SECONDS)
                .pollingEvery(pollingInterval, TimeUnit.MILLISECONDS)
                .ignoring(NoSuchElementException.class)
                .ignoring(ElementNotVisibleException.class)
                .withMessage("Fluent wait of " + waitingTime + " seconds with " + pollingInterval + " milliseconds polling interval was unable to locate element with locator " + locator);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(locator)));
    }

2 个答案:

答案 0 :(得分:0)

恭喜!你抓到了一个bug! ;)

我认为ExpectedConditions没有任何问题,但更有可能是页面的html发生了一些变化。

我会在FF上手动检查测试用例,看看有什么变化。

答案 1 :(得分:0)

轻松解决此问题的方法是将硒版本从3.1.0降级到3.0.1。