在Safari网页按钮使用AppleScript点击使用 [英] Using AppleScript click on safari web page button using

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

问题描述

我试图找出如何点击按钮的网页。例如点击在谷歌网页上的手气不错按钮。

I'm trying to figure out how to click on the button in a webpage. For example click on the "I'm Feeling Lucky" button in google web page.

这是我曾尝试:

告诉应用程序野生动物园
    使新文档具有属性{URL: https://www.google.com/ }

tell application "Safari" make new document with properties {URL:"https://www.google.com/"}

do JavaScript "eval(document.getElementById('I'm Feeling Lucky').parentNode.href.substring(11))" in document 1

delay 1

末告诉

但它不工作。任你知道我怎么可以点击使用AppleScript的按钮?

But it doesn't work. Any of you knows how can I click on the button using applescript?

我会真的AP preciate你的帮助

I'll really appreciate your help

推荐答案

几件事情:
在野生动物园告诉块最好的做法是还要告诉文件1.此外,有关谷歌该按钮的ID是错误的。下面是从页面code:

Couple things: Best practice in the safari tell block is to also tell document 1. Also, the ID for that button on Google is wrong. Here's the code from the page:

<button class="gbqfba" aria-label="Google Search" id="gbqfba" name="btnK"><span id="gbqfsa">Google Search</span></button>
<button class="gbqfba" aria-label="I'm Feeling Lucky" onclick="google.x(this,function() {google.ifl &amp;&amp; google.ifl.o();})" id="gbqfbb" name="btnI"><span id="gbqfsb">I'm Feeling Lucky</span></button>

在这里你可以看到ID的两个按钮是gbqfba'和'gbqfbb。但是,单击它们什么也不做,如果没有在搜索框中,然后改变了页面类型,并自动完成,我有主动,按钮永远需要点击。下面是一些code为yahoo.com网页是不是动态的。对于搜索按钮,搜索按钮ID有:ID =搜索提交...

where you can see the ID's for both buttons are 'gbqfba' and 'gbqfbb'. However, clicking them does nothing if nothing is typed in the search box, which then alters the page, and with auto-complete that I have active, the button never needs click. Here's some code for the yahoo.com page which is not dynamic. The search button ID for the search button there is: id="search-submit" …

tell application "Safari"
    activate
    make new document with properties {URL:"https://www.yahoo.com/"}
    delay 2

    tell application "System Events"
        keystroke "stackoverflow"
    end tell
    delay 0.3
    tell document 1
        do JavaScript "document.getElementById('search-submit').click();"
    end tell
end tell

在Chrome浏览器中做同样的信息是在这里:
<一href=\"http://stackoverflow.com/a/24644152/3097556\">http://stackoverflow.com/a/24644152/3097556

Info on doing the same in Chrome is here: http://stackoverflow.com/a/24644152/3097556

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

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