我试图自动化Google Docs登录过程,但我认为这样做的方法不会产生任何结果。代码如下。JavaScript中的AppleScript字符串连接
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
有问题的代码是execute javascript "document.getElementById('Email').value = '" & Username & "'"
。每当我尝试使用字符串连接执行JavaScript时,出现以下错误:“无法将{text returned:”hello“,button returned:”OK“}转换为Unicode类型文本。”
我也尝试使用下面的,而不是用keystroke
命令一起改变字段的值
execute javascript "document.getElementById('Email').click()"
。但是,这也没有用。我做错了什么,还是仅仅是AppleScript?
值得注意的是,下面的代码工作execute javascript "document.getElementById('Email').value = '" & "Hello" & "'"
。
这解决了这个问题。谢谢! – Josh 2012-07-25 14:47:53