【问题标题】:How to handle AutoSearch completion using Selenium webdriver如何使用 Selenium webdriver 处理自动搜索完成
【发布时间】:2013-12-02 11:34:18
【问题描述】:

我正在使用 JAVA 运行 Selenium Web 驱动程序,但遇到自动建议输入文本字段的问题。当我在文本字段中输入字符串“books”时,会显示一个选项。然后我想单击或选择自动建议菜单上填充的输入。

下面是代码:

WebDriver driver = new FirefoxDriver();

driver.get("http://www.amazon.com/");

driver.findElement(By.id("twotabsearchtextbox")).sendKeys("books");

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("gwcswTooltip")));

List<WebElement> findElements = driver.findElements((By.id("gwcswTooltip").name("books on")));

for (WebElement webElement : findElements)
{
  System.out.println(webElement.getText());
}

【问题讨论】:

  • 问题是?..

标签: java selenium selenium-webdriver


【解决方案1】:

您只需选择正确的定位器。

添加下面一行

List<WebElement> findElements = driver.findElements((By.xpath("//div[@id='srch_sggst']/div")));

而不是

List<WebElement> findElements = driver.findElements((By.id("gwcswTooltip").name("books on")));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 2017-01-29
    • 1970-01-01
    相关资源
    最近更新 更多