Applescript点击网页上的链接

时间:2014-07-23 05:31:09

标签: javascript click applescript

我正在尝试编写一个Applescript来自动从银行帐户下载帐户活动。我尝试过使用以下内容:

tell application "Safari"
    do JavaScript "document.getElementsByClassName(\"lnkDownloadTransactions.lightbox-launcher\").click();" in window 1
end tell

页面的HTML是:

<span class="download ui-flyout-activator ui-flyout-opened">

<a class="lnkDownloadTransactions lightbox-launcher" href="#" data-minwidth="600" data-height="590" data-lightbox=".lightbox-downloadtransactionsWidget" data-accountglobalid="X" data-laststatementdate="06/25/2014">

<span class="icon iconInbox">/span>

<span class="text">Download Transactions/span>

</a>

<input type="hidden" class="urlCtrlaccountsdownloadtransactionspartialview" value="/NFCU/accounts/downloadtransactionspartialview">

<section class="lightbox lightbox-downloadtransactionsWidget" style="position: static; display: none; width: auto; min-height: 0px; height: 496px;" title="Download Transactions">    section class="account-downloadtransactionsLightboxContent">  /section>

<footer class="account-downloadtransactions-footer">

<div class="actionButtons submitFields">

<button type="button" class="cancelbutton cancel account-downloadtransactions-cancel-button" href="#">Cancel/button>

<button class="button account-downloadtransactions-download-button">Download</button>
        </div>
    </footer>/section>/span>

但实际上并没有点击链接。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

班级名称在页面上不是唯一的。它将返回一个数组。使用ID。您可以看到answer here

tell application "Safari"
    activate
    tell document 1
        do JavaScript "document.getElementById('button-id').click();"
    end tell
end tell

您没有发布整个按钮代码,因此请勿查看该ID。