views:

55

answers:

2

There is a link on a html page with the following text

<Html>
...
<script type="text/JavaScript">
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function hide() {
    createCookie("ABC","1","7");
    document.location='abc.php';
}
</script>

<a style="color:#000;" rel="nofollow" href="abc.php?x=1" onclick="hide();return false;">My Link</a>
...

How to use Java to simulate a html "My Link" click ?

A: 

You can use HtmlUnit, which features a JavaScript evaluator and can thus work with in-page scripts.

Chris Jester-Young
A: 

Apart from the aforementioned HtmlUnit, you might use Selenium. At a company where I worked, we used it both for testing our web applications and for crawling javascript-based websites.

jkff