通过sendkeys传递文本后,我没有获得列表来选择项目。
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");
答案 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" );