Click the OK button on the javascript alert in the Chrome Browser

Please help, I haven’t found a solution for almost a month.

Is there a faster way to click the OK button on the JavaScript alert on Google Chrome?
I’ve tried all the ways, such as click activities, click image, find image and click, inejct vbs, cv click, click image trigger, keyboard shortcuts and all the activities provided. All the same, it still takes a long time to click the OK button.

@RQ_Official

Indicate window using a separate use app/browser and then try to use a click activity

Cheerd

I’ve tried it, but the result is still the same, it takes too long to click the “ok” button on the alert.

Thank you.

Why the Delay Happens

  • JavaScript alerts are blocking modal dialogs created by the browser.
  • UiPath waits for the alert to be rendered and available in the accessibility/UI tree , which often takes time or isn’t reliable.
  • Chrome prevents direct automation interaction with these alerts in many cases for security reasons.
    Soultion:
    After the alert appears, send an Enter key using Send Hotkey .
  • How:
  • Add a short delay (Delay activity – around 1–2 seconds).
  • Use Send Hotkey[Enter] (select browser window in the selector if needed).
  • This works 99% of the time because alerts are focused and pressing Enter triggers the “OK” button immediately.

I have also followed this method.
It does not run quickly and still waits for a long time up to 20 seconds to click the “ok” button on the javascript alert.

Thanks for the suggestion.

You can inject JavaScript code directly into the browser to auto-dismiss alerts.

  1. Enable “Inject JS Script” Activity
  2. Use the Inject Js Script Activity
    window.alert = function(){};
    window.confirm = () => true;

I just tried it and it takes longer.

Thanks for the suggestion

Try using classic click activity.

I use the modern one. How do I do that?

Create a separate workflow, use classic attach browser and click activity.
invoke this workflow in your main workflow.

have you tried reducing the timeout for click activity to say 2-3 seconds? I also faced similar kind of issue, this method worked for me.

Done.
The result is still the same.

The result is still the same.

Thanks for the suggestion

1 Like

You can try to modify and test classic click activity property like Input modes.

Hello @RQ_Official ,

Please try the new Browser Dialog Scope activity which handles JavaScript browser dialogs: alert, confirm or prompt. It is available in the new UIAutomation package v25.10.2.

Here is a guide on how this activity can be configured:

Best regards,
Luiza

Can you share your workflow