Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
549 views
Welcome To Ask or Share your Answers For Others

1 Answer

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...