在webdriver 2.21和mozilla11中处理警报 [英] Handling Alert in webdriver 2.21and mozilla11

查看:299
本文介绍了在webdriver 2.21和mozilla11中处理警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Firefox 11 + WebDriver 2.21.0 / WebDriver 2.22.0 (tried both).

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

In my scenario, when I click on a tab, it opens a confirmation box and on clicking OK it starts loading the new tab from server.

因此,我正在处理这种情况是:

So I'm handling this scenario as:

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

,但是在单击 mytab后,它将等待窗口无限期加载。因此它不会出现在 alert.accept()上,浏览器等待接受确认对话框以加载新页面,因此最终陷入了僵局。

but after it clicks on "mytab", it waits for window to load indefinitely. So it is not coming on alert.accept() and browser waits to accept the confirmation dialog to load the new page, so I end up in a deadlock condition.

此代码在Internet Explorer中效果很好。

This code works well in Internet Explorer.

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

Please help, how to deal the situation?

推荐答案

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

You, sir, might have found a bug (or at least an inconsistency) in Selenium WebDriver.

此处查找是否曾经在此找到,以及是否没有找到它错误,提交该文件

Look here whether it's been found before, and if there's no such bug, feel free to file it.

同时,您可以尝试加载 FirefoxDriver 使用不稳定的加载策略,然后(如果不够的话)可能 driver.manage()。timeouts()。pageLoadTimeout() (仅适用于设置为不稳定的Firefox)。

In the meantime, you can try loading FirefoxDriver with "unstable" loading strategy and then (if it's not enough) possibly driver.manage().timeouts().pageLoadTimeout() (which works only for Firefox with the "unstable" setting).

作为解决方法,您可以尝试通过JavaScript-尽管我不确定它是否会起作用:

As a workaround, you can try clicking the tab via JavaScript - though I'm not sure whether it will or won't work:

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

编辑:

作为另一种解决方法(受Selenium RC启发),您可以做什么?禁用确认对话框...

What you could do as another workaround (inspired by Selenium RC), you can temporarily disable confirmation dialogs...

// 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;");

这篇关于在webdriver 2.21和mozilla11中处理警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆