How to handle an alert when it is in a new window and if the window is not loaded fully. This window never loads successfully until unless accept/decline the alert.
What have you tried? What happened?
I’m not sure this will work… try calling switchToWindow* then immediately handle the alert
switchToWindowIndex
switchToWindowTitle
switchToWindowUrl
I tried all of these “switchToWindow”. In the console window, I can see it is working still “switchToWindow” but after that not able to accept the alert.
Can you click on the OK button in the console window instead?
No. After “switchToWindow” the click also not working.
1 Like
A couple ideas:
1.) After switching to the new window, do another switch to the alert modal and accept it:
// switch to new window first... then:
WebDriver driver = DriverFactory.getWebDriver();
driver.switchTo().alert().accept();
2.) Use desired capabilities to ignore all alerts:
Add this as an argument to your desired capabilities:
--disable-notifications
Here’s more info on how to add desired capabilities: