web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Cannot Automate JavaSc...
Power Automate
Unanswered

Cannot Automate JavaScript Alert (OK/Cancel Popup) in Browser with Power Automate Desktop

(0) ShareShare
ReportReport
Posted on by
I’m using Power Automate Desktop to automate a web process (government e-portal). After clicking a button, a JavaScript alert box (popup) appears with OK/Cancel. 
The recorder cannot capture this popup. 
Mouse clicks don’t work, only Enter key manually works. 
I tried 'Send keys' with {Enter} to Foreground window but it doesn't trigger the popup.
How can I auto-close this popup?
I have the same question (0)
  • Suggested answer
    TN-20081510-0 Profile Picture
    52 on at
    1)Are you able to inspect this popup?
    2)Once you get the id or class name of this popup ,use Run javascript to click on it.
    document.getElementsByClassName("classname")[i].click() 
     
    Here "i" is the index of classname.
     
     
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,844 Super User 2025 Season 2 on at
    Hi,
     
    Follow below steps:

    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:

    • Attach to your browser window (e.g., Chrome or Edge).

     Immediately after clicking the button that triggers the alert, insert:

    • “Send Keys” action

      • Target: The attached browser window

      • Keys: {Enter} 

     This often works if you give a small delay before sending keys.

     If needed, insert a “Delay” action before “Send Keys”:

    • 1–2 seconds (to wait for the popup to appear).

    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:

    window.alert = function(msg) {
    console.log('Auto-accepted alert:', msg);
    return true;
    };

    window.confirm = function(msg) {
    console.log('Auto-confirmed:', msg);
    return true;
    };

     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

     
     
     
     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard