简体   繁体   English

没有ID和名称的HTML按钮如何找到?

[英]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.

相关问题 如何找到没有名称或ID的唯一按钮? - How to find a unique button that has no name or id? 当按钮没有名称或 ID 时,我应该使用什么作为 `click()` 方法的参数? - What do I use as the argument for the `click()` method when the button has no name or ID? 当按钮没有ID和标题但具有悬停状态时,如何识别并单击Selenium Webdriver中的按钮? - How to identify and click to the button in selenium webdriver when button does not have id and title, but has hover state? 如何单击没有ID名称的按钮 - How to Click Button With out ID name 如何找到 html-table ID - How to find html-table ID 不幸的是,按下返回按钮后,项目名称已停止 - Unfortunately project name has stopped when pressing back button 当我们在html中有单个反逗号时,如何查找xpath:```sortable =”&#39;name&#39;”``` - How to find xpath when we have single inverted comma in our html Ex: ```sortable=“ 'name' ”``` 如何禁用没有ID和名称的桌面应用程序的文本字段 - How to disable text field of desktop application which has no Id and Name 如何在带有Java的Selenium中单击没有名称或ID的按钮 - How to click a button in selenium with java without name or ID 你好,我怎样才能得到按钮 DrawableTop 图标的名称或 ID? - Hello , How can I get the name or ID of a Button DrawableTop Icon?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM