Reputation: 39
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
Upvotes: 2
Views: 1040
Reputation: 13985
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.
Upvotes: 1