gpt4 book ai didi

java - 在 webdriver 2.21 和 mozilla11 中处理警报

转载 作者:行者123 更新时间:2023-12-01 05:17:30 24 4
gpt4 key购买 nike

我正在使用 Firefox 11 + WebDriver 2.21.0/WebDriver 2.22.0(都尝试过)。

在我的场景中,当我单击选项卡时,它会打开一个确认框,单击确定后,它会开始从服务器加载新选项卡。

所以我将这种情况处理为:

driver.findElement(By.id("myTab")).click();
driver.switchTo().alert().accept();

但是在单击“mytab”后,它会无限期地等待窗口加载。因此它不会出现在 alert.accept() 上,并且浏览器等待接受确认对话框以加载新页面,因此我最终陷入了死锁状态。

此代码在 Internet Explorer 中运行良好。

请帮忙,这种情况该如何处理?

最佳答案

先生,您可能在 Selenium WebDriver 中发现了一个错误(或者至少是一个不一致的地方)。

here以前是否发现过,如果没有这样的bug,请随意to file it .

同时,您可以尝试loading FirefoxDriver with "unstable" loading strategy然后(如果还不够)可能 driver.manage().timeouts().pageLoadTimeout() (仅适用于具有“不稳定”设置的 Firefox)。

作为解决方法,您可以尝试通过 JavaScript 单击该选项卡 - 尽管我不确定它是否有效:

((JavascriptExecutor)driver).executeScript("document.getElementById('myTab').click()");

<小时/>

编辑:

您可以采取另一种解决方法(受 Selenium RC 启发),您可以暂时禁用确认对话框...

// assuming your driver can handle JS ;)
JavascriptExecutor js = (JavascriptExecutor)driver;

// stores the original confirm() function and replaces it
js.executeScript("window.originalConfirm = window.confirm;"
+ "window.confirm = function(m) { return true; };");

driver.findElement(By.id("myTab")).click();
// it should not even fire the confirm and just proceed

// get the confirm back
js.executeScript("window.confirm = window.originalConfirm;");

关于java - 在 webdriver 2.21 和 mozilla11 中处理警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947857/

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