我的測試用於在2月20日之前正常運行。從今天早上開始,我在控制檯上看到許多錯誤。他們看起來像:ExpectedConditions類在運行硒測試時會拋出許多錯誤
лют. 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類。
項目編譯成功,我的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)));
}
你能後的'ExpectedConditions'使用在你的代碼的例子嗎? – Guy
@Guy我在說明中添加了一段代碼。感謝 –