Handling Alert in webdriver 2.21and mozilla11

删除回忆录丶 提交于 2019-12-13 19:21:33

问题


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();

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.

This code works well in Internet Explorer.

Please help, how to deal the situation?


回答1:


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.

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).

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


Edit:

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


来源:https://stackoverflow.com/questions/10947857/handling-alert-in-webdriver-2-21and-mozilla11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!