Can't dismiss browser alert; 'Prevent this page from creating additional dialogs' via automation

236 views
Skip to first unread message

Daryl Wray

unread,
Aug 3, 2015, 1:23:08 PM8/3/15
to Selenium Users
Context: 
- This alert is thrown by Chrome/Windows in response to an application alert being used for error reporting. The fact that the alert is being used for error reporting is an application bug and will be fixed (eventually). ...but the current situation is that this alert is thrown indefinitely, hanging our automation, in the absence of a means to dismiss it (via automation).
- The alert can not be dismissed via any of the generic webdriver or Java sendKeys mechanisms (e.g. Robot, driver.sendKeys(), etc.), as an UnhandledAlertException is thrown.
- alert.sendKeys() is unique from other webDriver.sendKeys() in that it takes a string, rather than an int.
- As an interactive user, I can check the ''Prevent this page from creating additional dialogs' check-box with a combination of <Tab> + <Space> keys. The <Tab> shifts the focus to the text check-box and the <Space> checks the check-box.

The only means to communicate with the alert, that I'm aware of, is alert.sendKeys(). I've tried the following to send a <Tab> to the alert via automation, with no success:

alert.sendKeys("\t");
alert.sendKeys("{TAB}");
alert.sendKeys("\uE004");
alert.sendKeys("\\U+0009");
alert.sendKeys(Integer.toString(KeyEvent.VK_TAB));

Any pointers on how to send a TAB to the alert are greatly appreciated!

Kaleem Uddin Mohammed Abdul

unread,
Aug 4, 2015, 1:40:47 AM8/4/15
to Selenium Users
Their is something called Keys.TAB.

Daryl Wray

unread,
Aug 5, 2015, 8:27:40 AM8/5/15
to Selenium Users
Thanks for the response! I'm aware of the Keys Class. Keys.TAB is an enum which translates to the CharSequence '\uE004'. Since alert.sendKeys() takes a String as argument, and not this enum, I was using the CharSequence directly as shown above ("\uE004") from the Unicode PUA table. I note that the keys class also has a toString() method, so I also tried alert.sendKeys(Keys.TAB.toString()). This also fails to deliver the tab to the alert.

Daryl Wray

unread,
Aug 7, 2015, 10:21:22 AM8/7/15
to Selenium Users
Final follow-up on this topic. I WAS able to dismiss this alert via java.awt.robot. The key was that, after the switchTo().alert(), that the timing for the robot must be correct. Here's the final robot code that allowed me to dismiss the browser's alert:
        robot.delay(500);
        robot.keyPress(KeyEvent.VK_TAB);
        robot.keyRelease(KeyEvent.VK_TAB);  
        robot.delay(500);
        robot.keyPress(KeyEvent.VK_SPACE);
        robot.keyRelease(KeyEvent.VK_SPACE);
Reply all
Reply to author
Forward
0 new messages