1

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?

Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
Akarsh
  • 19
  • 1
  • 7

1 Answers1

0

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;");
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • thanks for your reply Slanec. I tried using ((JavascriptExecutor)driver).executeScript("arguments[0].click()",element); but it also waits in the same way. – Akarsh Jun 11 '12 at 07:30
  • and when i tried using driver.manage().timeouts().pageLoadTimeout(). systen is not able to detect page load complete even after page is loaded it keeps on waiting and time out after specified time. – Akarsh Jun 11 '12 at 07:32
  • I'm sorry to hear that. I guess it's a bug, then. – Petr Janeček Jun 11 '12 at 07:43
  • Thanks it worked as a workaround on mozilla. same is not working in ie8. it throws modaldialogException after clicking "myTab". This way same test case won't be able to run on both browser. – Akarsh Jun 12 '12 at 13:03