我正在关注以下教程:http://cubemg.com/applescript/how-to-click-a-button-on-a-web-page-with-applescript/
我正在尝试制作一个加载网页并按名称单击按钮的脚本。 我的代码如下所示
tell application "Safari"
activate
do JavaScript "window.open('http://www.google.dk')" in document 1
end tell
to clickName(theName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByName(‘" & theName & "‘)[" & elementnum & "].click();" in document 1
end tell
end clickName
clickName("btnI", 0)
它只是在 safari 中打开页面,什么也不做。 Applescript 不断告诉我“缺失值”,但即使我只运行用于打开特定网站的代码,它也会这样做。 我创建了一个类似的代码来将值输入到表单中,但结果是相同的。
有人有同样的问题吗?
我多次检查了该按钮的名称,并在多个不同的网站上进行了尝试。
最佳答案
您的脚本中有拼写错误/错误。该行对单引号使用“智能引号”。这:
do JavaScript "document.getElementsByName(‘" & theName & "‘)[" & elementnum & "].click();" in document 1
应该是这个
do JavaScript "document.getElementsByName('" & theName & "')[" & elementnum & "].click();" in document 1
另外,您确实需要在加载网页后延迟一段时间,以确保元素已加载。
关于javascript - 使用 Applescript 在 Safari 中按名称单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33768105/