我有一个 Selenium 代码试图sendkeys()
我正在使用 firefox 35.0.1
和 selenium webdriver 2.44
和 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")
这会输入值并在我提交值之前将其删除。 尝试添加
d1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS)
- 我尝试过放置
Thread.sleep(x);
但没有任何效果,请帮助我。
最佳答案
单击文本字段后尝试使用 Thread.sleep,然后执行 sendKeys()。 如果这不起作用,请尝试等待文档完全加载。参见下面的函数:
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);
}
关于java - 当有多个发送键时,Selenium sendkeys 清除值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28184777/