[英]how to check if the form exists and print all the attributes of the form, HTMLUNIT JAVA
//coding in java //using htmlunit //在Java中编码//使用htmlunit
How to check if a form exists and then if it does how to print all the attributes so that it could be set to some value later. 如何检查表单是否存在,然后检查是否打印所有属性,以便以后可以将其设置为某个值。
The page i want to automate has a form that occurs with a different input id for a particular field everytime its refreshed 我要自动执行的页面具有一种形式,该形式在每次刷新时都会针对特定字段使用不同的输入id
getelementbyid("/ differs every time the page is refreshed /") getelementbyid(“ / 每次刷新页面时都会有所不同 /”)
and the element can be identified by its id only. 并且该元素只能通过其ID进行标识。
HtmlUnit supports xpath: getFirstByXPath()
which gives you a lot of flexibility for finding elements in XML or in this case HTML. HtmlUnit支持xpath:
getFirstByXPath()
,它为您提供了很大的灵活性,可以在XML或本例中的HTML中查找元素。
You can learn xpath here . 您可以在这里学习xpath。
As an example, if you wanted the second <input>
of the first <form>
on the page you could use //form[1]/input[2]
例如,如果您想要页面上第一个
<form>
的第二个<input>
,则可以使用//form[1]/input[2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.