4
votes

I have a scenario to create a new account, and I need to provide the account name in the popup and click "Ok".
I have used robot handling of the popup and on running the script, the alert closes and a new account is created, but getting the below error:

org.openqa.selenium.UnhandledAlertException: unexpected alert open (Session info: chrome=46.0.2490.86) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
(WARNING: The server did not provide any stacktrace information)

I have tried the below code:

///String handle= driver.getWindowHandle();
driver.findElement(By.xpath("//*[@id='createAccount']/p")).click();
Thread.sleep(300);
Robot rb =new Robot();
rb.keyPress(KeyEvent.VK_O);
rb.keyRelease(KeyEvent.VK_O);
rb.keyPress(KeyEvent.VK_U);
rb.keyRelease(KeyEvent.VK_U);
Thread.sleep(200);
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
Thread.sleep(400);
///driver.switchTo().window(handle);
//* Alert alt = driver.switchTo().alert();
//*alt.accept();
// driver.switchTo().alert().accept();
driver.findElement(By.id("passwd")).sendKeys("Abcd@123");    

The commented lines are the solutions I got from google, but that's also not working.

Additional info: When I do

Alert alt = driver.switchTo().alert();
alt.accept();

or

driver.switchTo().alert().accept();

I get the below error:

org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32603,"message":"Could not handle JavaScript dialog"} (Session info: chrome=46.0.2490.86) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)

1
I have the same problem. It happens randomly. - Nick Retallack

1 Answers

0
votes

Since thread.sleep() requires Exception handling, you're probably throwing the exception to the caller?

Also, since you say it works, but simply reports the other exception error, perhaps you should place the code in a try/catch and trap any sleep interruption exception (don't recall the exact wording) and then also the other exception that it does report, and simply ignore both of those exceptions, but throw any other exceptions encountered.

I realize the goal (usually) is to find the cause and fix it, for now at least it can be ignored.