Is there a way in java to "click" an html button for a specific url? I dont want to go through designing a GUI or opening a browser, I just want to write a program to "click" a button as a user would in a web browser for a specific website. Is the possible with a java program?
-
2You can see Selenium RC or Selenium WebDriver, but I'm not sure if it's exactly what you need, because these tools will open your browser to click on the buttonTako– Tako2013-03-23 03:46:15 +00:00Commented Mar 23, 2013 at 3:46
-
Ignore my vote to close as a duplicate, I misunderstood the question initially.FThompson– FThompson2013-03-23 03:51:47 +00:00Commented Mar 23, 2013 at 3:51
2 Answers
If I understood correctly .... you would like to emulate an interaction with the browser, programmatically. It's doable with java. You just need to open a http connection to the page's url you want to hit, with the expected form's parameters set up. Since it's a form it's easier and cleaner to do with post request.
You can use this library if you don't want to struggle with low level java api.
Comments
HtmlUnit is a great library offering such functionality, and its project page alone uses a description perfectly matching your question:
HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.
It is specifically a way to simulate a browser for testing purposes...
It even supports JavaScript. If that's a requirement for your project, HtmlUnit is worth looking into.