Reputation: 489
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<mpl=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" & "'"
.
Upvotes: 0
Views: 541
Reputation: 7191
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
Upvotes: 1