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.