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)
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:
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.
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.
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.
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.
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
------------------------------------------------------------
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.
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.
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.