Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically click a webpage button

Tags:

java

html

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?

like image 638
1478963 Avatar asked May 16 '13 13:05

1478963


1 Answers

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/

like image 153
BaconCookies Avatar answered Sep 19 '22 12:09

BaconCookies