1

I'm using Selenium webdriver java 2.45 and firefox 38 and when trying to handle an alert, it hangs forever.I've looked around for any prior answer to this and all I could find was this. He didn't get any answer and I couldn't comment to reiterate on the question, so please if anyone has encountered this problem your help will be greatly appreciated.

Unfortunately I cannot attach a code sample or any such thing as it is confidential, but the scenario is as follows: I fill a form that generates an alert upon submission and I use the following code to try to accept the alert:

try {
    (new WebDriverWait(driver_, timeout)).until(ExpectedConditions.alertIsPresent());
} catch (TimeoutException e) {
    throw new NoAlertPresentException();
} catch (Exception e1) {
    throw e1;
}

Alert alert = driver_.switchTo().alert();
String alertText = alert.getText();
if (dismiss)
    alert.dismiss();
else
    alert.accept();

As with the referenced question, this hung forever so I used the Java Robot class to dismiss the alert as follows:

try {
    Robot rb;
    rb = new Robot();
    rb.keyPress(KeyEvent.VK_ENTER);
    Thread.sleep(2000);
    rb.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException | InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

Unfortunately I get an UnhandledAlertException right after, so I don't know what to do. Trying to accept the alert with "driver_.switchTo().alert().accept" right after the Robot code only delayed the Exception generation.

If anyone has a solution, please help. If anything is unclear or if you have more questions about the situation I'd be glad to answer. I've been on this for 6 hours already.

Extra Information: The default alert management was working a day ago, just before the UI team in the company decided to go asynchronous for their Ajax calls. I don't know if this information is relevant at all but I figured more info is better than not enough info.

Community
  • 1
  • 1
Karl Fokum
  • 11
  • 2
  • Can you reproduce the issue on chrome? – Saifur Jun 02 '15 at 17:42
  • I haven't implemented my Selenium tests for Chrome. I'll try to switch to chromedriver and if this doesn't prove too time consuming I'll have an answer for you soon enough. – Karl Fokum Jun 02 '15 at 17:45
  • What kind of alert pops up there? Is it a browser based alert or OS based? – Priyanshu Jun 02 '15 at 17:48
  • @KarlFokum Then downgrade firefox. FF 38 is not officially supported by `Selenium` yet. There are a lot of open issues with latest ff and selenium 2.45 – Saifur Jun 02 '15 at 17:58
  • @Saifur I had the same problem with FF 34 before upgrading. I actually upgraded today while trying to find the cause of the problem. – Karl Fokum Jun 02 '15 at 18:28
  • @PriyanshuShekhar It is a browser based alert. It is generated by the Javascript "alert" function – Karl Fokum Jun 02 '15 at 18:29
  • @Saifur The switch to Chrome is proving difficult as I keep getting libGL errors amongst others when I try to launch with Chromedriver. Searching online indicates that this may be due to the fact that I run in VirtualBox. Unfortunately I can't change this as that is the development environment for the whole dev team here: Developing on Ubuntu 14.04 in VirtualBox installed on a Windows 7 machine. – Karl Fokum Jun 02 '15 at 18:36
  • 1
    @Saifur I just figured out the switch to Chrome and the problem doesn't occur with Chrome, meaning it's specific to Firefox. At least it seems so. – Karl Fokum Jun 02 '15 at 18:55
  • Yes. I am seeing lot of people having issues with firefox and selenium recently – Saifur Jun 02 '15 at 19:07

1 Answers1

0

Firefox version 30 is the best version for selenium webdriver. Downgrade firefox to 30 u will get over the issue

Ravi
  • 413
  • 1
  • 6
  • 11
  • I tried but that doesn`t work either. Same behaviour as in Firefox 34 and 38, it hangs forever as the alert pops up – Karl Fokum Jun 10 '15 at 16:17
  • @KarlFokum make sure u have made changes in the firefox settings for it not to upgrade. Go to **advanced Settings** in firefox and check on the **Never check for updates** – Ravi Jun 11 '15 at 05:52
  • I have. I only upgrade when I change my version of Selenium (or in this case, when a new problem arises and I need to check if it is related to the current browser version and has been fixed in a more recent one) – Karl Fokum Jun 15 '15 at 16:32