Srinivas Routh Srinivas Routh - 1 month ago 5x
Java Question

Selenium - Unable to find password field element based on CSS element on [a link]

I am trying to find password field element from a link using CSS selectors. Following is the code I used for other websites, it is working fine for all websites except the provided link.


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


The password field on that page is inside the iframe:

<iframe width="254" height="120" frameborder="0" src="" 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.findElement(By.xpath("//iframe[contains(@src, 'login.xhtml')]")));

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