1

I am working with Htmlunit for auto-fill-out-form. 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. 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'. That solved the problem. Thanks for all answers.

Israel Cohen
  • 81
  • 3
  • 3
  • 8
  • 1
    You want to access it where client side/server side..? using what..? – T J Jun 09 '14 at 10:11
  • Its Htmlunit and in Java. I am using it for auto fill out forming. You have to detect the element in your page before performing an operation on it. That is the element which I want to be detected by Java – Israel Cohen Jun 09 '14 at 10:13
  • If you look at the code it has an access key called "s". But when I try to detect it by access key it gives the error that I am introducing a string instead of a char. I dont know what to do. – Israel Cohen Jun 09 '14 at 10:18
  • why don't you use class name to detect the element – ashok_p Jun 09 '14 at 10:20
  • Because there are dozens of buttons with the same class name – Israel Cohen Jun 09 '14 at 10:25
  • if there is a form first select that form and then select submit. – ashok_p Jun 09 '14 at 10:27
  • You can ADD any classes that you want do make them diferent. class='button buttonToDetect' – DanielPanic Jun 09 '14 at 10:28
  • u need something unique value in your tag which may be id or name – AmanS Jun 09 '14 at 10:33
  • you can use jquery $("input[tabindex='104']") or in javascript you can use this code http://snipplr.com/view/1853/get-elements-by-attribute/ or this code http://stackoverflow.com/questions/9496427/can-i-get-elements-by-attribute-selector-when-queryselectorall-is-not-available – rjdmello Jun 09 '14 at 10:34

3 Answers3

0

Why not alter your HTML to add an id attribute. That is, consider altering your application so it is easier to test.

Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • How could I alter the application when its a remote website that is not mine? is this possible? – Israel Cohen Jun 09 '14 at 10:40
  • 1
    If it is not yours, in the broadest sense, why are you testing it at all? If you are part of an independent test team, ask the developers to alter the code on your behalf. – Raedwald Jun 09 '14 at 10:42
  • I am not testing it Sir. I am trying to auto fill out a form and send it. But there is no possibility to detect the element. – Israel Cohen Jun 09 '14 at 10:44
0

you can't do it, without passing an attribute to it, either give it an id or a name. That would help you,

Amrinder Singh
  • 5,300
  • 12
  • 46
  • 88
0

Here "0" means it the first input type element.

var but = document.getElementsByTagName("input")[0]; //index of input type element 
console.log(but.value);
Tusar
  • 759
  • 5
  • 21