簡體   English   中英

JavaScript中的AppleScript字符串串聯

[英]AppleScript string concatenation in JavaScript

我正在嘗試自動執行Google Docs登錄過程,但是我認為可以使用的方法沒有任何效果。 代碼如下。

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

有問題的代碼是execute javascript "document.getElementById('Email').value = '" & Username & "'" 每當我嘗試使用字符串連接執行JavaScript時,都會出現以下錯誤:“無法使{文本返回:“ hello”,按鈕返回:“ OK”}變成Unicode文本類型。

我也嘗試使用以下內容代替更改字段的值
execute javascript "document.getElementById('Email').click()"以及keystroke命令。 但是,那也不起作用。 我是在做錯什么,還是只是AppleScript?

值得注意的是,以下代碼有效
execute javascript "document.getElementById('Email').value = '" & "Hello" & "'"

因為display dialog命令的結果是一條記錄。

要獲取字符串,請使用以下命令:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM