gpt4 book ai didi

java - Webdriver FluentWait 不忽略异常

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:35 28 4
gpt4 key购买 nike

我已经自动化了一些通过此页面的用户流程 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));
}

有时我会收到超时异常,因为找不到元素 (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     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"}

如有任何帮助或建议,我们将不胜感激。

最佳答案

FluentWait 实际超时时,您不能抑制 TimeoutException。这就是 API 的本质。如果这是您真正想要忽略的异常,则需要捕获 TimeoutException

此外,作为旁注,尝试每纳秒轮询一次条件可能会适得其反。您可能应该将轮询间隔延长到大约每 200 或 250 毫秒一次。

关于java - Webdriver FluentWait 不忽略异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20468865/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com