I'm facing below error while handling an alert pop up with Chrome driver in Selenium.
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : Save successfully.}
Scenario:
This is happening when two alerts appears immediately.
First alert pop up appears and I'm handling it with :
Alert alertf = driver.switchTo().alert();
alertf.accept();
Immediately the next alert appears and I have used wait and then implemented another alert
Alert alert2 = driver.switchTo().alert();
alert2.accept();
But this fails.
Execution is stopping at 1st alert.
Complete Error:
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : Save successfully.}
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds: null
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'KADALI7', ip: '15.75.149.101', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.44.609538 (b655c5a60b0b54..., userDataDir: C:\Users\kadali\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:2130}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 71.0.3578.98, webStorageEnabled: true}
Session ID: 2175d3b0d47212f94e61f6e71c8ca535
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:172)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:4
If ignoring the alert will not affect your scenario, you can simply ovverride alert method to overcome the issue by executing javascript code before the alert which is causing the error exactly:
window.alert = function() {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With