Selenium not able to find out "" password textbox ""

1,898 views
Skip to first unread message

gourav nahata

unread,
Sep 1, 2011, 6:39:46 AM9/1/11
to Selenium Users
Hello Sir ,

I am stuck in selenium automation script can you please guide.

We have two elements on a webpage. Text field to enter username ,
and password textbox. Selenium is finding the username field pretty
well but not the password field. Code for these two fields are as
follows:-

<p>
<label for="username">Username</label>
<input id="username" class="autoclear autoclear-default" type="text"
autocomplete="off" value="Username" name="username"/>
</p>

<p>
<label for="password">Password</label>
<input id="password" class="autoclear" type="password"
autocomplete="off" value="Password" name="password" style="display:
none;"/>
<input id="password" class="autoclear autoclear-default" type="text"
autocomplete="off" value="Password" style="display: inline;"/>
</p>


We are giving the following values to detect these fields:-

Username id username
Password id password


Can you please suggest what could be the reason

Thanks & Regards
Gourav Nahata
07838090535

Mark Collin

unread,
Sep 1, 2011, 6:44:54 AM9/1/11
to seleniu...@googlegroups.com
To start with does the page pass a W3C validation? If not the DOM may well
be corrupted which is stopping selenium from finding the element.

http://validator.w3.org/

Hello Sir ,

--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Gourav Nahata

unread,
Sep 1, 2011, 7:01:17 AM9/1/11
to seleniu...@googlegroups.com
Hi Mark ,
 
I am very new to selenium. 
 I checked using xpath finder  and I tried using " //p[2] "  it finds the element but when use it in the excel sheet it throghs an error " Class not found "
 
And mark can you please tell me how this validator works.  I think issue is not with this as it is finding the other text field of username.
 
Thanks & Regards
Gourav Nahata
07838090535
Gourav Nahata

Mark Collin

unread,
Sep 1, 2011, 7:18:41 AM9/1/11
to seleniu...@googlegroups.com

The validator will check if your HTML is W3C compliant.  If it is not it will show you any errors.

 

If you have broken HTML you will have a broken DOM, modern browsers try to fix it on the fly but they are into guesswork territory where each browser will guess differently with varying degrees of success.  Just because you can find one text field is no guarantee that you will be able to find any others if your markup is invalid (the browser may have guessed one field correctly but got the other one wrong).

 

The xpath you have supplied is looking for a paragraph, not an input box.  A valid xpath would be:

 

//input[@id=’password’]

 

Check to see if that works.

 

If none of this helps you will need to show us your test script.

Gourav Nahata

unread,
Sep 1, 2011, 7:30:27 AM9/1/11
to seleniu...@googlegroups.com
Hi All  ,
 
Some how I believe I am able to make selenium find the reuired  password text box using
 
//p[2]/input[@id='password' and @class="autoclear autoclear-default"]
 
but now selenium is setting some wrong password I guess . I am finding this in the logs when my script runs. But password is not getting set in the required text box . Can you please suggest. Eclipse Logs is showing following logs:-
 

Object for which execution will be done is Password  ( According to my script)

Set 'Password' as '*********'

Thanks & Regards
Gourav Nahata

Mark Collin

unread,
Sep 1, 2011, 7:50:15 AM9/1/11
to seleniu...@googlegroups.com

Try not to key into classes as they change, an ID is the most secure way of finding an element using XPath.  The one I supplied below should work, does it?

 

You have still not told us if you have run the page in question through a validator to see if it is valid HTML and we cannot give you any more help unless you supply your test script (the HTML of the page you are testing may be useful as well).

Gourav Nahata

unread,
Sep 1, 2011, 9:02:29 AM9/1/11
to seleniu...@googlegroups.com
Hi Mark,
 
I tried validating the webpage but as it is on client network it is not getting validated and showing proxy error.

And yes I tried finding the element by xpath that you sent . Element is getting detected now but now password is not getting set into the text field.
 
 
 
Thanks & Regards
Gourav Nahata

Mark Collin

unread,
Sep 1, 2011, 11:50:09 AM9/1/11
to seleniu...@googlegroups.com

I find the easiest way to get round issues like that are to download and use the Web Developer toolbar in FireFox, one of the options it gives you is validate local HTML so the validator doesn’t need to have access to the website you are testing it will just take a copy of the page and send it over to the validator.

 

The validator is also downloadable so that you can run an instance locally on your network if required.  I would strongly suggest that any company making websites should do this as a basic W3C validation will throw up lots of potential problems that can easily be fixed with minimal effort.

 

Can you provide your test script?  If you do we can see what you are trying to do and try to find an answer for you.

Gourav Nahata

unread,
Sep 2, 2011, 12:42:33 AM9/2/11
to seleniu...@googlegroups.com
HI Mark,
 
I have attached the code for testdriver.java and the html source code of the page I m trying to  test . Please have a look at it.
 
When we see the page source it shows the following code for password text field:-
 
<p>
          <label for="password">Password</label>
          <input type="password" name="password" id="password" class="autoclear" value="Password" autocomplete='off' />
        </p>
 
But when we see the code using inspect element it shows following code for the password textbox
 
<p>
<label for="password">Password</label>
<input id="password" class="autoclear" type="password" autocomplete="off" value="Password" name="password" style="display: none;"/>
<input id="password" class="autoclear autoclear-default" type="text" autocomplete="off" value="Password" style="display: inline;"/>
</p>
 
 
Please have a look at it. Password is not getting enetered into the text field.
 
Thanks & Regards
Gourav Nahata
7838090535
Code_Testdriver.txt
htmlcode.htm

Mark Collin

unread,
Sep 2, 2011, 4:09:27 AM9/2/11
to seleniu...@googlegroups.com

I’ve had a quick look through this and I can’t see where in your test you are trying to interact with the input element with an id of password , in fact the majority of what you have supplied appears to be extracting data from an Excel spread sheet.

 

Where is the code for your test?

Reply all
Reply to author
Forward
0 new messages