使用 JavaScript |Applescript 在 Safari 中单击按钮 [英] Using Javascript | Applescript to click button in Safari

查看:49
本文介绍了使用 JavaScript |Applescript 在 Safari 中单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到有几个关于此的主题,它们都非常特定于某个网站.我的背景是 Python,而不是 Javascript 或 Applescript,我对如何实现此操作感到困惑.

I realize there are several threads about this and they are all very specific to certain website . My background is in Python, not Javascript or Applescript, and I'm confused on exactly how to achieve this action .

我见过几个执行此操作的脚本,即:

I've seen several scripts doing this action, namely:

tell application "Safari"

activate

do JavaScript "document.forms['search']['order_list_search_batch'].click()"

end tell

执行此操作的最佳方法是什么?

What is the best method to act this out ?

我对 "document.forms[WHATGOESHERE?].click()"

我正在尝试点击 http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi.

我转到继续"按钮上的检查元素"并获得此代码:

I went to "Inspect Element" on the Proceed button and got this code:

<input style="cursor: pointer;" value="" name="proceed" class="proceed" onmouseover="this.style.cursor=&quot;pointer&quot;" type="submit">

我如何知道在脚本中放入什么内容以根据 Inspect Element 结果单击此按钮? 我想了解以便我可以在不止一种情况下使用此方法.它没有指向的 href 链接.

How do I know what to put in script to click this button based off of the Inspect Element results ? I want to understand so I can use this method in more than one case. There's not a href link that it goes to.

当前代码无效

tell application "Safari" to activate
open location "http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi"
delay 3
tell application "Safari" to do JavaScript "document.forms[0].elements[document.forms[0].elements.length-1]"

推荐答案

document.forms['search']['order_list_search_batch'].click()

document.forms['form']['proceed'].click()

如果您检查继续按钮,您会发现它位于具有name"属性且值为form"的表单元素内.按钮本身有一个name"属性,值为proceed".因此,在您的 JavaScript 中,括号中的第一个术语查找名为form"的表单,第二个术语指的是form"-form 中名为proceed"的元素.如果这有任何意义;-)

If you inspect the proceed button, you'll find that it's inside a form element with a "name" attribute with the value "form". The button itself has a "name" attribute with the value "proceed". So in your JavaScript, the first term between brackets looks for the form named "form" and the second one refers to the element named "proceed" inside the "form"-form. If that makes any sense ;-)

此外,您还必须告诉 AppleScript 在哪个文档中执行 JavaScript.如果没有其他选项卡打开,您刚刚打开的文档可能是文档 1.

Also, you will have to tell AppleScript in which document to execute the JavaScript. The document you just opened will probably be document 1, if there are no other tabs open.

希望这有帮助!

完整代码:

tell application "Safari"
activate
open location "http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi"
delay 3
do JavaScript "document.forms['form']['proceed'].click()" in document 1
end tell

这篇关于使用 JavaScript |Applescript 在 Safari 中单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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