我有一個腳本,可以在新的Safari窗口中打開URL列表,但JavaScript命令似乎不起作用。我卡在一個console.log文件中,該文件不會在檢查器中顯示,也不會顯示出來。我試着改變了JavaScript之前的延遲,一直到17。JavaScriptScript命令在AppleScript中工作
作爲一個備註,'subscribe-button'是編輯按鈕,當你登錄,我想點擊。
on run {input, parameters}
read (item 1 of input)
set ps to paragraphs of the result
set tot to count ps
tell application "Safari"
reopen
activate
end tell
repeat with i from 1 to tot
set p to item i of ps
if p is not "" then
try
tell application "Safari"
tell front window
set r to make new tab with properties {URL:p}
set current tab to r
delay 1
do JavaScript "console.log('test this log')"
do JavaScript "document.getElementsById('subscribe-button').click()"
if i = tot then exit repeat
repeat
delay 1
get URL of r
end repeat
end tell
end tell
end try
end if
end repeat
end run
如果您需要幫助調試代碼,您應該提供[最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)。 – user3439894
這真的是無益的評論,但我仍然回答自己的問題。 – VagueExplanation
我沒有任何問題在我已經應用到的網頁中,使用JavaScript中的'do JavaScript'document.getElementsById('elementID')。click()「在文檔1中單擊使用JavaScript中的JavaScript按鈕。至於我對** MCVE **的評論,這幾乎是** SO **的潛規則,但有時提醒是必要的! **您沒有提供URL來測試您的代碼,或查看目標頁面中的代碼,所以我所能提供的是反覆爲我和其他人工作的內容。** – user3439894