以编程方式单击网页按钮 [英] Programmatically click a webpage button
问题描述
如何以编程方式点击Java中的网页按钮?
给定此按钮:
< div id =titlebutton> Button< / div>
在Javascript中,它可以这样工作:
< pre class =lang-javascript prettyprint-override> var newWin = window.open(siteYouHaveAccessTo);
newWin.document.getElementById('titlebutton')。click();
我想知道如何在Java中执行此操作,而不是Javascript(有没有这样做的方法单独使用Java还是必须导入/使用Javascript?)。
编辑:
单击按钮将导致调用一个名为setText()的函数。
我不确定我会如何发送类似的请求作为这个函数?
如果我粘贴了函数代码,会有帮助吗?
单独使用Java,这就是我们使用JavaScript的原因。如果您想要控制浏览器,例如点击按钮并填写文本字段,则必须使用自动化工具。使用Java的自动化工具是Selenium。这通常用于测试自动化,但会做你想做的事情。
请参阅 http://docs.seleniumhq.org/
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/
这篇关于以编程方式单击网页按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!