簡體   English   中英

嘗試填寫網絡表單的applescript預期出現行尾錯誤

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

我試圖提出一個我可以運行的Apple腳本,以便填寫每天執行的某些Web表單(JIRA票證表單)。

我創建了這個JS腳本,當我在Chrome的控制台上運行該腳本時,該腳本可以正常工作:

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

因此,現在我創建了自己的applescript,以便能夠在外部執行它,但是我始終會收到“語法錯誤。期望行尾等,但發現未知標記”

這是代碼:

tell application "Google Chrome"

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

end tell

我知道告訴應用程序有效,但是我不明白如何解決語法錯誤並使applescript有效

in document 1語法適用於Safari。

使用Google Chrome瀏覽器時,您應該轉到目標windowactive tab ,例如:

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

或將窗口號替換為其name

使用最新版本的Sierra對我有效

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

-僅壓縮為一行代碼

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

我選擇此代碼的原因是由於以下示例。

在Google Chrome瀏覽器中,我從一個窗口開始,然后從一個帶有4個標簽的窗口開始。 接下來,將這些選項卡拆分為4個單獨的窗口。 之后,我選擇了右下角的窗口,使其成為“活動窗口”。 認為右下角的窗口現在處於活動狀態,將成為“第1窗口”……我錯了(根據以下腳本的結果)

在此處輸入圖片說明

如果我在“ window 1”中運行腳本,它將在瀏覽器的左上方窗口中運行,當我只有一個帶有一個選項卡的窗口時,它就是窗口1。 它保留了其初始值。 問題是不是我要在其上運行腳本的窗口

在此處輸入圖片說明

因此,顯然窗口1不一定是前窗

暫無
暫無

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

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