在selenium webdriver中使用sendkeys后无法获取列表

时间:2014-02-15 00:52:08

标签: html css selenium

通过sendkeys传递文本后,我没有获得列表来选择项目。

  1. 你能告诉我,问题是什么。
  2. 网站是www.kuoni.co.uk

  3. WebElement createHolidayText = driver.findElement(By.cssSelector("div[class=\"span12 sections\"] >ul > li > a[data-section-id=\"972cfe76_6ba0_408d_a6df_0ef2d74cf943\"] > span"));
    assertThat("Create Holiday Text has changed. Please check!", createHolidayText.getText(), is("Create your holiday"));
    
    WebElement clickCreateYourHoliday = driver.findElement(By.cssSelector("div[class=\"span12 sections\"] >ul > li > a[data-section-id=\"972cfe76_6ba0_408d_a6df_0ef2d74cf943\"] > span"));
    clickCreateYourHoliday.click();
    
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("iframe[src=\"http://booking.kuoni.co.uk/include/home/include-book-home11.html\"]")));
    
    WebElement searchFrame = driver.findElement(By.cssSelector("iframe[src=\"http://booking.kuoni.co.uk/include/home/include-book-home11.html\"]"));
    driver.switchTo().frame(searchFrame);
    
    WebElement destination = driver.findElement(By.cssSelector("input[id=\"destination\"]"));
    destination.sendKeys("SSH");
    

1 个答案:

答案 0 :(得分:0)

我通过你的代码遇到了同样的问题。

问题是当iframe被打开时 - 目标文本框花费时间来填充检索数据的所有条目。

我使用了以下代码,它对我有用:

  driver.get("http://www.kuoni.co.uk");
      WebElement createHolidayText = driver.findElement(By.cssSelector("div[class=\"span12 sections\"] >ul > li > a[data-section-id=\"972cfe76_6ba0_408d_a6df_0ef2d74cf943\"] > span"));
      assertThat("Create Holiday Text has changed. Please check!", createHolidayText.getText(), is("Create your holiday"));

      WebElement clickCreateYourHoliday = driver.findElement(By.cssSelector("div[class=\"span12 sections\"] >ul > li > a[data-section-id=\"972cfe76_6ba0_408d_a6df_0ef2d74cf943\"] > span"));
      clickCreateYourHoliday.click();

      WebDriverWait wait = new WebDriverWait(driver, 30);
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("iframe[src=\"http://booking.kuoni.co.uk/include/home/include-book-home11.html\"]")));

      WebElement searchFrame = driver.findElement(By.cssSelector("iframe[src=\"http://booking.kuoni.co.uk/include/home/include-book-home11.html\"]"));
      driver.switchTo().frame(searchFrame);
      Thread.sleep(2000);
      WebElement destination = driver.findElement(By.cssSelector("input[id=\"destination\"]"));
      destination.click();
      Thread.sleep(6000);
      destination.sendKeys("SSH" );
      destination.sendKeys(Keys.BACK_SPACE);
      destination.sendKeys("H" );