2014-02-15 72 views
-1

通過sendkeys傳遞文本後,我沒有獲取列表以選擇該項目。在selenium webdriver中使用sendkeys後無法獲取列表

  1. 請問,請問這是什麼問題。
  2. 網站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, 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

我通過你的代碼得到了同樣的問題。

問題是何時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"); 
相關問題