java - 当有多个发送键时,Selenium sendkeys 清除值

标签 java selenium-webdriver sendkeys

我有一个 Selenium 代码试图sendkeys()
我正在使用 firefox 35.0.1selenium webdriver 2.44eclipse 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")  

这会输入值并在我提交值之前将其删除。 尝试添加

  1. d1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS)
  2. 我尝试过放置 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/

相关文章:

c# - Selenium C# : Not able to click on an element within #shadow-root (closed) which appears when user mouse over

selenium - webdriver.firefox.marionette 和 webdriver.gecko.driver 之间的区别

java - 滚动到 WebElement 并单击它

android - 当测试按下开始按钮时游戏没有开始

python - selenium.common.exceptions.ElementNotInteractableException : Message: element not interactable while sending text to contenteditable div element

java - 为什么从 maven2 迁移到 buildr 时我的测试无法运行?

java - 如何将属性文件中的数据加载到bean属性值中?

winapi - 如何将击键发送到窗口而无需使用 Windows API 激活它?

java - 将字符串转换为 double - JAVA

java - 在 Java 8 中反转比较器