2

I am trying to find password field element from a link http://www.cartasi.it/gtwpages/index.jsp using CSS selectors. Following is the code I used for other websites, it is working fine for all websites except the provided link.

 pwd=driver.findElement(By.cssSelector("input[type='password']")) 

and checked the source code of the website but i did not find any type="password" keyword in the code. i feel like posting source code of entire website would create chaos hence gave the link to refer. What could be causing this password hidden? How can I locate the element using CSS selector? Any help would be greatly appreciated

5
  • I opened the page, and was not able to see any sort of login form. Are you sure there is a password field on that page? Commented Sep 18, 2016 at 17:07
  • you can find username and password at top right of the page. Commented Sep 18, 2016 at 17:14
  • Source code of the website is not displaying any input fields . Is there any reason for hiding the code for those elements? if so how is it possible and how can firebug get the entire source code of website including all the input fields. Any help or clarification would be greatly appreciated Commented Sep 18, 2016 at 17:17
  • I was able to get a reference to it in the browser console using document.querySelector("input[type='password']"). Not sure about Selenium though. Commented Sep 18, 2016 at 17:21
  • Thanks for your response and time but i am into selenium working. Commented Sep 18, 2016 at 17:43

1 Answer 1

1

The password field on that page is inside the iframe:

<iframe width="254" height="120" frameborder="0" src="https://titolari.cartasi.it/portal/login/login.xhtml" marginheight="0" marginwidth="0" scrolling="no">
...
<input id="loginForm:password" class="ui-inputfield ui-password ui-widget ui-state-default ui-corner-all" type="password" tabindex="2" placeholder="" name="loginForm:password" role="textbox" aria-disabled="false" aria-readonly="false">

So you need to switch to iframe first and then use your selector:

driver.switchTo().defaultContent(); // make sure you are on main page
driver.switchTo().frame(
    driver.findElement(By.xpath("//iframe[contains(@src, 'login.xhtml')]")));
pwd=driver.findElement(By.cssSelector("input[type='password']")) 

Of course you can change the xpath / selection method to whatever you prefer.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your answer, it helped me to understand the difference between source code and inspect element code in browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.