KM Not Recognizing Chrome Prompt

I'm unable to determine how to make KM interact with a Chrome prompt (i'm attaching images). I need to select the textbox in the prompt, enter the word 'confirm' and click the OK button. I've tried numerous actions that should work but KM does not seem to be able to interact with the prompt. Any suggestions? Any help will be greatly appreciate.

I've tried the following actions:

The prompt's textbox seems to have focus when it loads. After the prompt loads, if I start typing manually without clicking on the textbox, text is entered into the field. My assumption was that I should be able to use the "Insert Text by Typing" action once the prompt loads, but that did not work. So I attempted to use all of the following to give the prompt's textbox focus:

Focus Google Chrome Field
Select Google Chrome Field
Move and Click (on textbox - relative to front windows top left corner)
Move and Double Click (on textbox - relative to front windows top left corner)
Move and Click (on textbox - absolute position)
Move and Double Click (on textbox - absolute position)

None of these worked.

Here is my current setup:

Here is the prompt:

Hey James,

When troubleshooting something like this:

  • Create a single action macro to test the problem area.

In your case see if insert text by typing (or pasting) works when you've manually brought up the dialog.

If that works then you have other fish to fry.

Disable all your actions but one.

Run the macro.

Enable the next action.

Run the macro.

And so on.

Put judicious pauses in the macro.

Just because the action says wait until loaded doesn't mean it managed perfectly. Check.

The actions you have after “Click link ‘Delete Campaign’” may be happening before the dialog shows up.

Put in a Pause Until action until button “OK” exists.

Many problems like yours occur because of timing issues.

If none of that works then holler.

-Chris

Hi Christopher,

Thank you for the helpful reply. I have followed your advice and am able to have the macro fill in the text once I have manually opened the prompt.

First I tried opening the prompt manually and using a single action: "Insert Text 'confirm' by Typing". This worked as expected.

Next I tried opening the prompt manually and using two actions: "Insert Text 'confirm' by Typing" and "Type the Enter Keystroke". This also worked as expected (entering the text and submitting the form/prompt).

However, as soon as I add the action “Click link ‘Delete Campaign’” (to automate opening the prompt) the macro never seems to be able to move to any actions that follow in the list.

The issue is occurring after the “Click link ‘Delete Campaign’” and before all other actions. I added the "Pause Until button "OK" exists" action like you suggested, but it did not help.

The macro seems halt immediately after the “Click link ‘Delete Campaign’” action. To test this, I've setup various other actions following the “Click link ‘Delete Campaign’” action. For instance, I've setup a "Activate a Specific Application" action to try and activate some other application after the “Click link ‘Delete Campaign’” action occurred. The Macro never progresses to the "Activate a Specific Application" action. Note: I've tried this test with and without the "Pause Until" action in place.

Any additional guidance would be greatly appreciated.

This Macro seems to halt after the “Click link ‘Delete Campaign’” action:

Hey James,

You can use "gear" menu

to receive more error information.

Hope this help,
-- Alain

Hey James,

So you're saying the Click Google Chrome Link action is completely failing?

You've tried it in isolation?

-Chris

@ccstone

If I activate the Chrome prompt manually and then run only the actions “Insert Text ‘confirm’ by Typing” and “Type the Enter Keystroke”, the macro is able to complete these actions.

However, once I add the actions that automate opening the prompt, everything seems to halt once the prompt has opened.

Hey James,

That kind of issue is very frustrating.

Unfortunately I'm out of ideas – especially since I can't test it myself.

-Chris

@ccstone

I really appreciate your help and insight. I’ve uploaded a walkthrough of the issue here: https://youtu.be/kSghW7qsu7w in the hopes that it will spark an idea.

-James

Hey James,

That looks like it could be a bug. (Peter?)

Okay, let's see if we can work around it.

First try putting a pause BEFORE the pause until action. Give it a couple of seconds. (It's possible Keyboard Maestro is firing before the dialog can receive the text.)

If that doesn't work then get the delete dialog open and run this AppleScript in the Script Editor.app.

tell application "System Events"
  tell application process "Google Chrome"
    tell front window
      {properties, UI elements}
    end tell
  end tell
end tell

Post the result from the Script Editor's result panel.

-Chris

If you can adjust your windows so you can see the Keyboard Maestro editor at the same time as you perform the macro, you will be observe the value of the condition “(currently true)” and “(currently false)”. Make sure it is false before the macro, and then perform the macro and you will be left with the confirm dialog displayed with the OK button, check whether it is true at that point.

What happens if at that point with the confirm box still being displayed, you type on the keyboard? What happens if you trigger a macro that simply types “confirmed”? Do they work.

You might also like to include a notification action after the Pause Until to verify when it is happening. My guess would be that the pause is too short and the typing is happening before the application is ready to receive the text, but you said you included a long pause there and that still didn’t work, which would exclude that possibility.

@ccstone @peternlewis Hey guys, thanks for trying to help me get this solved. I'm attaching screen captures of what you guys suggested.

In the first screen capture, I had the macro click the "delete campaign" link. As you can see, the "Pause Until" remained false. Chris - I also ran the script that you suggested and you can see the results in the screen capture.

The second screen capture shows that when I manually click on the link, the "Pause Until" changes to true.

Hey James,

Okay.

Change your Pause Until action to this:

Pause Until.kmactions (1.2 KB)

NOTE:

This is an ACTION file NOT a macro, so it will import directly into the macro open for editing in the KM editor.

Try running this AppleScript from an Execute an AppleScript action.

Create a new test macro with ONLY that action.

Open your dialog in Chrome.

Run the macro, and see if it works.

------------------------------------------------------------
try
  
  tell application "System Events"
    tell application process "Google Chrome"
      set theDialogWindow to the first window whose subrole is "AXDialog"
      tell theDialogWindow
        tell text field 1
          set its value to "confirm"
        end tell
        delay 0.1
        tell button "OK"
          perform action "AXPress"
        end tell
      end tell
    end tell
  end tell
  
on error e number n
  set e to e & return & return & "Num: " & n
  if n ≠ -128 then
    try
      tell current application to set ddButton to button returned of ¬
        (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
          default button "OK" giving up after 30)
      if ddButton = "Copy Error Message" then set the clipboard to e
    end try
  end if
end try
------------------------------------------------------------

Let me know how you get on.

-Chris

If the script works then add in your click link action, and see if that works.

-Chris

The script works on it’s own. If I manually open the dialog and then run the “Execute AppleScript” action, it works just fine. But as soon as I add the “Click Link” action, everything comes to a halt once the dialog opens. I got the following error:

System Events got an error: Can’t get window 1 of application process “Google Chrome” whose subrole = “AXDialog”. Invalid index.

Num: -1719

Hey James,

That’s highly irritating and seeming more and more like a bug.

I think Peter should see the vid, so you might want to repost it.

Have you tried any of this in Safari instead of Chrome?

All Chrome actions are AppleScript under-the-hood, and Chrome’s AppleScript implementation can be flakey at times.

If you want to try it I’ll need you to run the System Events script again and post the result – just the text is fine.

Change “Google Chrome” in the script to “Safari”.

-Chris

I will try Safari and let you know. Here is the link to the second walkthrough I recorded this morning.

The Click Link action is just a simple AppleScript that calls a JavaScript that finds the element and then calls click() on it.

The action waits for the AppleScript/JavaScript to complete. So I would guess that the click is synchronously calling the dialog and not returning until the dialog is complete.

This is not really the behaviour you’d expect since if you click on a link manually, you’d expect the system to carry on, so I will endeavour to change it so instead of calling click() directly, it calls it asynchronously and returns immediately.

Basically just:

setTimeout(function() { obj.click(); }, 0);

In the mean time, you can try setting the timeout on the action to 1 second and no failure or report and see if that works.

Or you can do the click asynchronously manually using the Execute JavaScript action.

Hey James,

Download this macro: Click on the first web page item that matches an XPath

Install it for testing.

Do you know how to use the web inspector in Chrome?

Right-click on the element in a webpage you wish to look at and then choose the “Inspect” item from the contextual menu.

Then right-click on the highlighted element, go to the “Copy” submenu, and select “Copy Xpath”.

Paste that Xpath into your test macro.

Run it, and see if it works.

If it works select “asynchronously” from the results menu in the run javascript action and add it to your production macro.

-Chris

@peternlewis @ccstone

YOU GUYS ARE AMAZING!!!

It was the async issue. I downloaded the macro you suggested Chris, copied the Xpath into it, then set execution to async and now it’s working. The macro is now able to recognize the prompt after the automated click on the “Delete Campaign” link.

Bravo! I sincerely appreciate all the help you guys gave me.

James