Domanda

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();

  }
È stato utile?

Soluzione

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");

Altri suggerimenti

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);

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
cvvTxtBox().sendKeys("1234"); 
cvvTxtBox().sendKeys(Keys.TAB);

Final Solution on this problem.
Else use Robot

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top