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)