Applescript : Click at position not working



I'm trying to click on a Chrome extension ( Google Highlight : then click on the text box and past my variables.

here is my code

set NoteforGoogleCHrome to "My text should be there"

tell application "Google Chrome"
end tell
tell application "System Events"
    tell process "Google Chrome"

        delay 2
        click button 8 of toolbar 2 of window "myTab" of application process "Google Chrome" of application "System Events"
        delay 0.2
        keystroke tab
        delay 0.2
        keystroke NoteforGoogleCHrome
        delay 0.2
        keystroke space
    end tell
end tell

I tried this but this is most of the time failing.

When I'm trying to click on the text field (CLICK 2) I always have an error :

click process "Google Chrome" at {4000, 114} –> missing value

However if I do the same for CLICK 1 I have no error.

Can you give me some advice ?

Best Answer

The following works for me in macOS High Sierra 10.13.5 and Google Chrome 67.0.3396.99.

Example AppleScript code:

set NoteforGoogleCHrome to "click me"

tell application "Google Chrome" to activate
delay 0.5
tell application "System Events"
    click (every UI element of toolbar 2 of front window of application process "Chrome" whose help is "Multi-highlight")
    delay 1
    key code 48 -- # Tab Key
    delay 0.2
    keystroke NoteforGoogleCHrome & space
end tell

As you can see in the image below, it highlighted all occurrences of click and me.

enter image description here