How to programmatically click a webpage button in Java?
Given this button:
I'm not sure if this is what you are looking for, but if what you are looking to do is simply make a HTTP request in Java, this should do the trick:
HttpURLConnection urlConnection = null;
URL urlToRequest = new URL("http://yoursite.com/yourpage?key=val&key1=val1");
urlConnection = (HttpURLConnection) urlToRequest.openConnection();
urlConnection.setConnectTimeout(CONN_TIMEOUT);
urlConnection.setReadTimeout(READ_TIMEOUT);
// handle issues
int statusCode = urlConnection.getResponseCode();
if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
// handle unauthorized (if service requires user login)
} else if (statusCode != HttpURLConnection.HTTP_OK) {
// handle any other errors, like 404, 500,..
}
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
// Process response
Replace the timeout constants with your own values, and the URL to match that of your website. You can send any data you want to send with the click of the button as query parameters in the URL in the form of key/value pairs.