AppleScript“缺失值"中的Javascript(用于Safari中的单击按钮) [英] Javascript within AppleScript 'missing value' (for clicking button in Safari)
问题描述
我有以下包含Javascript的AppleScript:
I have the following AppleScript with Javascript contained:
set buttontext to "Add Option"
set buttonloc to 1
tell application "Safari"
activate
tell window 1
do JavaScript "var buttonTags = document.getElementsByTagName(\"button\");
var searchText = \"" & buttontext & "\";
var found;
for (var i = 0; i < buttonTags.length; i++)
{if (buttonTags[i].textContent == searchText) {
found = buttonTags[i]; break;
}
}
buttonTags[" & buttonloc & "].click();"
end tell
end tell
它可以正常编译,但是在执行时没有任何动作,并且我收到缺少值"错误.它旨在在Safari中浏览网页,并允许用户指定按钮文本和等级以便能够单击它.
It compiles fine but upon execution there is no action and I receive a 'missing value' error. It is designed to traverse a web page in Safari and allow a user to specify the button text and rank to be able to click it.
直接在Safari的开发控制台中执行此Javascript时,它可以工作,但是我需要在AppleScript中将其包装到更长的例程中.
When execute this Javascript directly in Safari's dev console it works, but I need to have it in AppleScript to wrap it into a longer routine.
建议感激!
推荐答案
我设法通过将JS的末尾修改为:
I have managed to solve this with amending the end of the JS to:
buttonTags[" & buttonloc & "].click();" in current tab
这篇关于AppleScript“缺失值"中的Javascript(用于Safari中的单击按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!