Option 1: Send Keys to Browser Process
Instead of sending keys to the “Foreground window,” send keys to the actual browser process.
This works better because PAD then directs the keystroke to any modal dialog owned by the process.
Steps:
Use the “Attach to running window” action:
Immediately after clicking the button that triggers the alert, insert:
This often works if you give a small delay before sending keys.
If needed, insert a “Delay” action before “Send Keys”:
Option 2: Use Shortcut Instead of Click
Sometimes triggering the action via keyboard shortcut or JavaScript injection (instead of mouse click) makes the alert more easily handled.
-
For example, if pressing a key combination triggers the same event, try Send Keys to trigger it.
-
Or use “Run JavaScript function on web page” to trigger the action.
Why?
This keeps focus in the automation context rather than a separate OS modal.
Option 3: Fallback—Use External Script to Auto-Close Alerts
If none of the above work (very common on secure portals), you can pre-inject a script that suppresses or auto-accepts all alerts.
How?
Use a “Run JavaScript function on web page” action before the button click:
This overrides alert() and confirm() to do nothing.
Caution:
-
This technique works only if the site doesn’t prevent overrides.
-
On government portals with CSP restrictions, it might be blocked.
If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
Regards,
Riyaz