Dismissing Browser Alerts with ChromeDriver

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
NickD
Pro Scripter
Posts: 58
Joined: Fri Sep 23, 2016 2:17 pm

Dismissing Browser Alerts with ChromeDriver

Post by NickD » Wed Apr 01, 2020 2:13 pm

Do we have any method of detecting and dismissing browser alert windows with ChromeDriver?

I'm not sure where to start trying to detect an active Alert(). The alert locks the page when active so you can't use the inspector in dev tools, and does not exist in the dom as an element when not active, because alerts are created by javacript....

I know that Kantu (a Selenium based chrome automation addon) gets around alerts by automatically clicking "OK" on alerts as default, then allowing users to override this default behaviour with a different click target, eg: chooseCancelOnNextConfirmation if required.

Because alerts block all interaction with the page until dismissed there is certainly logic in this approach.

If I could detect and target an active alert I am pretty sure:

Code: Select all

ChromeSetElementValue>session_id,AlertElement_1,\uE007
would dismiss it, but without a target element, that idea is a non-starter.

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Dismissing Browser Alerts with ChromeDriver

Post by Marcus Tettmar » Wed Apr 01, 2020 6:45 pm

An alert box is not an HTML element, it's a regular windows dialog. So stick to the basics:

Code: Select all

SetFocus>test.html*
Wait>0.5
Press Enter
Adjust window title accordingly.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts