user2256973
user2256973

Reputation: 1

Selenium sendkeys clearing out values when there are multiple sendkeys

I have a selenium code trying to sendkeys()
I am using firefox 35.0.1 and selenium webdriver 2.44 and eclipse Luna

WebDriver d1 = new FirefoxDriver()
d1.get("www.xx.com")
WebElement username=d1.findElement(By.xpath(".//*[@id='login_username']/input"))     
WebElement password=d1.findElement(By.xpath(".//*[@id='login-assword']/input"))    
username.sendKeys("admin")      
password.sendKeys("welcome")  

This enters the values and deletes it before I submit the values. tried adding

  1. d1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS)
  2. I've tried putting Thread.sleep(x);

but nothing is working please help me out.

Upvotes: 0

Views: 365

Answers (1)

user4501512
user4501512

Reputation:

Try using Thread.sleep after clicking into the text field and then do a sendKeys(). If that doesn't work, try waiting until the document is loaded entirely. See below function:

void waitForPageLoad(WebDriver driver)
{   
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() 
{       
public Boolean apply(WebDriver driver)
{
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};  
wait.until(pageLoadCondition);    
}

Upvotes: 1

Related Questions