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

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

问题描述

我意识到有几个关于这个问题的线索,并且他们都对某个网站非常具体。我的背景是在Python中,而不是Javascript或Applescript,我对如何实现这个动作感到困惑。



我看过几个脚本正在执行这个动作, :

 告诉应用程序Safari

激活

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

end tell

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



我对文档之间的内容感到困惑。表单[WHATGOESHERE?]。click()



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

我在继续按钮上点击检查元素,得到以下代码:

 < input style =cursor:pointer; value =name =proceedclass =proceedonmouseover =this.style.cursor =& quot;指针& quot;类型= 提交 > 

如何知道如何在脚本中点击此按钮元素结果?我想理解,所以我可以在多个案例中使用此方法。这里没有href链接。





目前的代码无效

  tell应用程序Safari激活
打开位置http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi
延迟3
告诉应用程序Safari要做JavaScriptdocument.forms [0] .elements [document.forms [0] .elements.length-1]


<解决方案

更改您的JavaScript查询

  document.forms ['搜索'] ['order_list_search_batch']。click()

to



pre $ document $ form $'$'$' >

如果您检查了继续按钮,您会发现它位于一个带有name属性且值为form的表单元素中。该按钮本身具有名称属性,其值为继续。因此,在JavaScript中,括号之间的第一个术语查找名为form的表单,第二个术语在form-form内引用名为proceed的元素。如果这是有道理的; - )

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



希望这有助于您!



整个代码:

 告诉应用程序Safari
激活
打开位置http: //rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi
delay 3
JavaScriptdocument.forms ['form'] ['proceed']。click() in document 1
end tell


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 ?

i'm confused on what goes in between "document.forms[WHATGOESHERE?].click()"

I'm trying to click the Proceed button on 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">

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.

Current code is not working

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]"

解决方案

Change your JavaScript query from

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

to

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

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 ;-)

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.

Hope this helps!

The entire code:

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天全站免登陆