0

I'm trying to automate the Google Docs login process, but the methods that I thought would work yield nothing. The code is as follows.

display dialog "Username" default answer ""
set Username to the result
display dialog "Password" default answer "" with hidden answer
set myPassword to the result
tell application "Google Chrome"
    tell window 1
        set newTab to make new tab with properties {URL:"https://accounts.google.com/ServiceLogin?service=writely&passive=1209600&continue=https://docs.google.com/?tab%3Dwo%23&followup=https://docs.google.com/?tab%3Dwo&ltmpl=homepage"}
        repeat 50 times --wait until the page loads...
            delay 0.1
        end repeat
        tell active tab
            execute javascript "document.getElementById('Email').value = '" & Username & "'"
        end tell
    end tell
end tell

The code in question is execute javascript "document.getElementById('Email').value = '" & Username & "'". Whenever I try to execute the JavaScript using string concatenation, I get the following error: "Can’t make {text returned:"hello", button returned:"OK"} into type Unicode text."

I've also tried to use the following instead of altering the field's value
execute javascript "document.getElementById('Email').click()" along with a keystroke command. However, that didn't work either. Am I doing something wrong, or is it just AppleScript?

It is worth noting that the following code works
execute javascript "document.getElementById('Email').value = '" & "Hello" & "'".

1 Answer 1

1

Because the result of the display dialog command is a record.

To get a string, use this :

display dialog "Username" default answer ""
set Username to text returned of the result
display dialog "Password" default answer "" with hidden answer
set myPassword to text returned of the result
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.