如何使用htmlunit单击javascript按钮? [英] How do I click a javascript button with htmlunit?

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

问题描述

我正在开发一个应用程序,它将使用Java中的htmlunit自动单击网页上的按钮。唯一的问题是该按钮是一个javascript按钮,因此标准的getInputByName()将不起作用。处理这个的任何建议?该按钮的代码包含在下面。

I'm working on an application that will automatically click a button on a webpage using htmlunit in Java. Only problem is that that button is a javascript button, so the standard getInputByName() won't work. Any suggestions with dealing with this? The code for the button is included below.

<a class="vote_1" id="1537385" href="/javascript%3Avoid%280%29/index"><img src="/images/parts/btn-vote.gif" alt="Btn-vote" /></a> 

此外,这是投票的其他代码。

In addition, here's the other code for voting.

<div id="content"><script type="text/javascript" src="/js/scriptFeeds/voteArticle.js"></script> 

这导致以下javascript:

Which leads to the following javascript:

var pressed = new Array();

$j(document).ready(function() {
var nr = $j("input#number_of_articles").val();
for(var i=1; i<=nr; i++){
    $j("a.vote_"+i).click(function(){
        var article   = $j(this).attr("id");
        $j('#'+article).hide();
        if (!pressed[article]) {
            pressed[article] = "yes";
            jQuery.post('/vote-article', {
                _token: $j("#_token").val(),
                article_id: article
            },function(data) {
                $j("span.numberOfVotes_"+data.id).html(data.votes);
            }, "json");
        }
        return false;
    });
}
});


推荐答案

尝试将此addOn用于firefox,它会记录您的操作并为其生成HTMLUnit代码。可能会有所帮助。
http://code.google.com/p/htmlunitscripter/

Try using this addOn for firefox, it records your actions and generates the HTMLUnit code for the same. may be it could help. http://code.google.com/p/htmlunitscripter/

这篇关于如何使用htmlunit单击javascript按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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