Wei Shi
Wei Shi

Reputation: 5055

Simulate a click on JavaScript function in Java

I'm writing a program that interacts with a website automatically in Java. I figured out how to build and send GET/POST requests to simulate a click or form submit. But I encountered a link that runs a JavaScript function.

<a href="javascript:function()">Run</a>
function function()
{
    document.myform.submit();
}

After clicking, the webpage is redirected to another URL. How do I simulate this behavior in Java?

Upvotes: 0

Views: 245

Answers (2)

Rymos
Rymos

Reputation: 56

I've always had the best luck with HTMLUnit. It uses apache http and handles all the interaction pretty intuitively.

Upvotes: 2

artbristol
artbristol

Reputation: 32397

Use an existing library like Selenium or HttpClient to interact with a website.

Upvotes: 1

Related Questions