gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:58:20 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com