7

I am trying to learn selenium webdriver automation but I am finding that the sendKeys command is not typing on Password type fields. I can see that some other people are also experiencing the same problem by googling it, but I haven't seen any correct answer yet. Could anyone please help me here.

Please find below sample code; I generated code from Selenium IDE and its working fine on IDE but not when I use webdriver.

package com.example.tests;

public class Login {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://www.webs.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testLogin() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.cssSelector("span")).click();
    driver.findElement(By.id("FWloginUsername")).clear();
    driver.findElement(By.id("FWloginUsername")).sendKeys("aug2qatestingqa@yahoo.com");
    driver.findElement(By.id("FWloginPassword2")).clear();
    driver.findElement(By.id("FWloginPassword2")).sendKeys("webs");
    driver.findElement(By.id("sign_in_leaf")).click();

  }
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Anoop Philip
  • 971
  • 2
  • 11
  • 19
  • What do you mean by "Not working"? Does it throw an error, or simply not type it in? – Nathan Merrill Aug 02 '13 at 17:54
  • Sorry, I should have more specific. It simply not type in it. – Anoop Philip Aug 02 '13 at 17:57
  • 1
    I don't know what is wrong. Are you absolutely sure its not typing it in? It may be running too fast that you cannot see it typing/logging in. I would recommend debugging it and running it command by command. – Nathan Merrill Aug 02 '13 at 18:01
  • 1
    Your id for the password field is FWloginPassword2 which makes me suspect that perhaps its not looking at the right element? Is therea FWloginPassword element without the 2? – Nathan Dace Aug 02 '13 at 18:17
  • Yes there is FWloginPassword and FWloginPassword2 fields. If I use FWloginPassword2 and click on password field then it starts typing on it. So I think webdriver can't identifying the field. – Anoop Philip Aug 02 '13 at 18:28
  • @MrTi : org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 30.10 seconds – Anoop Philip Aug 02 '13 at 18:47
  • Ah, it found it, but it is not visible. I believe that PocketDews is correct. Try typing in FWloginPassword. If that doesn't work, inspect the element (Chrome: Right-click->inspect element) and try to find a different element to select. – Nathan Merrill Aug 02 '13 at 18:52
  • 1
    Found a solution but it actually weird. When I click FWloginPassword and then sendkeys command starts typing on FWloginPassword2 field. driver.findElement(By.id("FWloginPassword")).click(); driver.findElement(By.id("FWloginPassword2")).sendKeys("webs"); Thanks MrTi and @PocketDews – Anoop Philip Aug 02 '13 at 20:05
  • Hi Anoop Philip: glad to hear that you've found a solution. It's best if you post it as an answer, and then accept that answer; it helps everybody see the solution clearly, and marks the question as answered. – Vince Bowdren Aug 05 '13 at 08:44

4 Answers4

0

There were two password fields and one is hidden. Solution is to click on first password [hidden] field to get second password field enabled.

driver.findElement(By.id("FWloginUsername")).sendKeys("aug2qatestingqa@yahoo.com");
driver.findElement(By.id("FWloginPassword")).click();
driver.findElement(By.id("FWloginPassword2")).clear();
driver.findElement(By.id("FWloginPassword2")).sendKeys("webs");
Anoop Philip
  • 971
  • 2
  • 11
  • 19
0

I had almost a similar situation for Password field. There were two elements for the same 'Password' field but with different IDs. The JavaScript was toggling "type = password" on run time for a click, clear or any action to this field.

Solution in this case is to find the text with input type = password,

for example:

driver.FindElement(By.CssSelector("input[type='password']")).SendKeys(IWebElement);
Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
0

My problem was that I used ActionChains which caused the later fields not being filled when using send_keys method.

The solution was to call actions.reset_actions()

e.g.

actions = ActionChains(driver)
actions.key_down(Keys.LEFT_CONTROL).send_keys("a").perform()
actions.key_down(Keys.LEFT_CONTROL).send_keys("c").perform()
actions.reset_actions()

# now send_keys() method works again
Boy
  • 1,182
  • 2
  • 11
  • 28
-3
cvvTxtBox().sendKeys("1234"); 
cvvTxtBox().sendKeys(Keys.TAB);

Final Solution on this problem.
Else use Robot

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Paggy
  • 1