AppleScript“缺失值"中的 Javascript(用于单击 Safari 中的按钮) [英] Javascript within AppleScript 'missing value' (for clicking button in Safari)

查看:28
本文介绍了AppleScript“缺失值"中的 Javascript(用于单击 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆