Ily*_*tel 5 java selenium-webdriver
我通过此页面http://www.efinancialcareers.co.uk/search自动化了一些用户流程.当我使用左侧精炼轨道缩小搜索范围时,会出现一个覆盖图,用户必须等到返回搜索结果.该方法等待叠加层出现,然后等待它消失.
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));
}
Run Code Online (Sandbox Code Playgroud)
有时我得到一个Timeout异常,因为找不到元素(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
});
Run Code Online (Sandbox Code Playgroud)
并删除它
$('body').unblock();
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
Caused by: org.openqa.selenium.TimeoutException: Timed out after 5 seconds waiting for com.efinancialcareers.myefc.desktop.BasePage$6@548238e0
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"}
Run Code Online (Sandbox Code Playgroud)
任何帮助或建议将不胜感激.
TimeoutException当FluentWait实际超时时你无法抑制.这只是API的本质.如果这是一个你真正想忽略的例外,你需要抓住它TimeoutException.
此外,作为旁注,尝试每纳秒轮询一次这种情况可能会适得其反.您应该将轮询间隔延长到每200或250毫秒.