How to programmatically click a webpage button in Java?
Given this button:
<div id="titlebutton" >Button</div>
In Javascript it would work like this:
var newWin = window.open(siteYouHaveAccessTo);
newWin.document.getElementById('titlebutton').click();
I was wondering how I would do this in Java, not Javascript (Is there a way of doing it with Java alone or do I have to import/use Javascript?).
Edit:
Clicking the Button will result in a call of a function called setText(). I am not sure how I would send a similar request as this function? Would it help if I pasted the function code?
You can't 'programmatically' click a button with Java alone, which is why we use JavaScript. If you want to get into controlling the browser such as clicking buttons and filling text fields you would have to use an automation tool. An automation tool that uses Java is Selenium. This is typically used as for test automation, but will do what you want it to do.
See http://docs.seleniumhq.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With