Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the above code is my html code of the Password Text field so, How Can I locate the Element by xpath

What I have tried:

I am trying to automate the my web application, so while locating the element of Password I am getting "FAILED: login
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 10.59 seconds"
Please help me to resolve the Issue
Posted
Updated 21-Jul-17 5:52am
Comments
Dave Kreskowiak 20-Jul-17 12:57pm    
Ummm... The "above code" where?
prem yadav 21-Jul-17 0:14am    
www.servicesathi.com in this web site, I am trying to do automation on my project... in that go to Registration and that code is for Password Filed

1 solution

You've provided no code but I image the issue is related to the following

* You've got two password textboxes with no id's. This is fine but it makes it extremely hard to target
* You've got two password textboxes, 1 for login, 1 for registration. You've indicated in your comments you get the error on registration page saying the element is hidden. It is because it is targeting the first text box under login instead of the second one under registration

You don't indicate what language you are using selenium with so I'll provide my examples in C#

The way i see it, you've got two solutions

1) Add unique Id's to the two password textboxes that you have. ex: txt-login-pwd for the login screen and then txt-registration-pwd for the registration password modal window.

That way in selenium you can simply target it by doing driver.FindElement(By.Id("txt-login-pwd")); or driver.FindElement(By.Id("txt-registration-pwd"));.

2) If you've got full control over this website I don't know why you wouldnt just add id's to the password textboxes but in the event you feel opposed to that, this is your other option which is entirely more work than simply adding Id's to your two password textboxes.

To see what i mean by the fact that you have to find something that makes your password textboxes unique which the only thing I see is type="password". You'll need to figure out the proper XPATH syntax for this.

Note, i'm typing this from memory so it may or may not compile but the code will point you in the right direction

C#
var pwdTextBoxes = driver.FindElements(By.Xpath("//input[@type='password']"));
var count = pwdTextBoxes.Count();


At this point you'll see cound should say 2. Thats because of your login/registration textboxes.

You'll need to know which index of the pwdTextBoxes list/array is for registration and login screen respectively. From there, you'll be able to targe the correct one.

Example: var loginPwdTxtBox = pwdTextBoxes[0]; would be the login password textbox and then var registrationPwdTxtBox = pwdTextBoxes[1]; points to the registration textbox and you can take whatever action on it that you need at that time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900