简体   繁体   中英

Expected end of line error on applescript trying to fill a webform

I'm trying to come up with an apple script I can run in order to fill out some web forms I do every day (JIRA ticket forms).

I've created this JS script which is working when I run it on Chrome's console:

document.getElementById('summary').value="Inserted text"

So now I create my applescript in order to be able to externally execute it but I always get "Syntax Error . Expected end of line, etc. but found unknown token ."

This is the code:

tell application "Google Chrome"

execute javascript document.getElementById('summary').value="Inserted text" in document 1   

end tell

I know tell application works, but I don't understand how to solve the Syntax Error and make the applescript work

The in document 1 syntax is for Safari.

With Google Chrome you should to talk to the active tab of the target window , eg:

tell application "Google Chrome"
    tell active tab of window 1
        execute javascript "document.getElementById('summary').value = 'Inserted text';"
    end tell
end tell

Or substitute the window number with its name .

This works for me using the latest version of Sierra

tell application "Google Chrome"
    execute front window's active tab javascript "document.getElementById('summary').value = 'Inserted text';"
end tell

OR - Compacted down to one line of code only

tell application "Google Chrome" to execute front window's active tab javascript "document.getElementById('summary').value = 'Inserted text';"

The reason I chose this code is because of this following example..

In Google Chrome I started out with one window, then one window with 4 tabs. Next, Split up those tabs into 4 separate windows. After this, I selected the bottom right window to make that the “active window”. Thinking that, that bottom right window, being active, would now be “window 1”… I would be wrong (according to the results of this following script)

在此处输入图片说明

If I ran the script in “window 1” it would have run on the upper left window in the browser, which was window 1 when I only had one window with one tab. It retained its initial value. The problem is that is not the window I wanted to run my script on

在此处输入图片说明

So apparently window 1 is not necessarily the front window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM