[英]How to find a Html button when it has no ID and Name?
I am working with Htmlunit for auto-fill-out-form. 我正在与Htmlunit一起使用自动填写表格。 There is a submit butoon with the following code:
有一个带有以下代码的提交按钮:
<input type="submit" class="button" value="Log in" tabindex="104" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" />
unfortunately when I try to detect the element, there is no possibility to detect and recognize it by Tabindex or Title. 不幸的是,当我尝试检测元素时,无法通过Tabindex或Title检测和识别它。 When I try access key it returns an error mentioning that I am entering a string rather an access key.
当我尝试访问密钥时,它返回一个错误,提示我正在输入字符串而不是访问密钥。 So what should be done?
那应该怎么办呢? Thanks for help.
感谢帮助。
Update: Ok. 更新:好的。 I solved the problem myself.
我自己解决了这个问题。 It's possible to detect the element by access key.
可以通过访问键检测元素。 But instead of "s", it should be 's'.
但是,它应该不是“ s”,而是“ s”。 That solved the problem.
那解决了问题。 Thanks for all answers.
感谢所有答案。
Why not alter your HTML to add an id
attribute. 为什么不修改HTML以添加
id
属性。 That is, consider altering your application so it is easier to test. 也就是说,考虑更改您的应用程序,以便于测试。
you can't do it, without passing an attribute to it, either give it an id or a name. 如果不给属性传递名称或名称,就无法做到这一点。 That would help you,
那对你有帮助
Here "0" means it the first input type element. 此处的“ 0”表示它是第一个输入类型元素。
var but = document.getElementsByTagName("input")[0]; //index of input type element
console.log(but.value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.