我有自動它通過http://www.efinancialcareers.co.uk/search此頁轉到一些用戶流量。 當我使用左側精煉導軌縮小搜索範圍時,會出現疊加層,用戶必須等待直到搜索結果返回。該方法等待疊加層出現,然後等待它消失。的webdriver FluentWait沒有忽略例外
public void waitForSRPOverlayToComplete() {
Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriver())
.withTimeout(5, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.NANOSECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
**// Error occurs here**
WebElement blockedOverlay = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.className("blockOverlay"));
}
});
Wait<WebDriver> wait2 = new FluentWait<WebDriver>(getDriver())
.withTimeout(5, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.NANOSECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
wait2.until(ExpectedConditions.stalenessOf(blockedOverlay));
}
有時我得到一個超時異常的元素(blockOverlay)未找到。當這種情況發生時,我觀察了頁面,覆蓋層確實出現了,但我認爲有時當搜索非常快時,上述方法會錯過它。 我不明白爲什麼我會遇到技術錯誤,因爲我已經說了一口流利的等待忽略它們。
這是爲了覆蓋的代碼出現:
$('body').block({
message: $('#loaderEl'),
css: {
backgroundColor: 'transparent',
border: "none",
color: '#333333',
fontWeight: 'bolder',
top: ($(window).height() - $('#loaderEl').height())/2 + $(window).scrollTop() + "px"
},
overlayCSS: {
backgroundColor: '#f8f8f8'
},
centerY: false
});
,並刪除它
$('body').unblock();
這是錯誤我收到:
Caused by: org.openqa.selenium.TimeoutException: Timed out after 5 seconds waiting for [email protected]
Build info: version: '2.35.0', revision: '8df0c6bedf70ff9f22c647788f9fe9c8d22210e2', time: '2013-08-17 12:46:41'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_26'
Driver info: driver.version: unknown
... 33 more
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"blockOverlay"}
任何幫助或建議將不勝感激。
我不知道我是如何看到代碼「複雜」的。當超時被評估('if(!clock.isNowBefore(end))'')時,如果超時已經到期,則拋出'TimeoutException',這是另一個創造性地稱爲'timeoutException()'的類中的方法返回的值。 。該方法將傳播的實際異常作爲參數,該異常由前一個異常處理塊捕獲。請注意,此代碼塊位於任何try-catch之外,因此不受忽略給定類型的異常的代碼影響。 – JimEvans
@JimEvans - 謝謝。我反應過快。我保持冷靜,迅速掃描了代碼並編輯了我的答案。代碼並不像我想的那樣難以理解。 – testerjoe2