【问题标题】:sendkeys() enters text and clears it in an auto-complete search fieldsendkeys() 输入文本并在自动完成搜索字段中清除它
【发布时间】:2013-02-25 21:00:17
【问题描述】:

我无法让 webdriver 在基于自动完成的搜索文本字段中输入一些文本。 我正在使用以下代码:

//here elmt is a WebElement variable.
elmt = driver.findElement(By.id(testDataMap.get("globalSearchTextLocator")));
elmt.sendKeys(patientName);

//Here I am finding the search result list once webdriver enters the characters.
elmt = driver.findElement(By.cssSelector(testDataMap
.get("searchPatientNameLocator")));


searchedPatientsList = driver.findElements(By.cssSelector(testDataMap
.get("searchPatientNameLocator")));

我还尝试在elmt.sendKeys() 之前使用elmt.click()。它在我运行测试的时候随机运行了几次。但大多数情况下,它失败了。 发生的情况是 webdriver 将文本输入搜索字段并在下一刻将其清除。这导致没有搜索结果并且测试失败。我无法追踪这种奇怪行为背后的问题。有什么帮助吗?提前致谢!

【问题讨论】:

    标签: autocomplete webdriver selenium-webdriver browser-automation


    【解决方案1】:

    我遇到过类似的问题,但它是针对数字字段的。尝试使用下面的代码并执行你的脚本。

    String accOffNoID = OR.getProperty("AccOffNo_ID"); 
            WebElement accOffNoInput = driver.findElement(By.id(accOffNoID));
            accOffNoInput.clear(); 
            accOffNoInput.sendKeys(String.valueOf(9874651230L));
            accOffNoInput = driver.findElement(By.id(accOffNoID));
    

    根据您的脚本更改名称并执行,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-16
      • 2019-10-25
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      相关资源
      最近更新 更多