2017-04-16 6 views
0

カレンダーリストから日付の値を選択できません。その他のテストはすべて動作しています。セレンテスト - カレンダーリストから値を選択できません

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.support.ui.Select; 

public class ch1 { 
    public static void main(String[] args) throws InterruptedException { 
     // TODO Auto-generated method stub 
     System.setProperty("webdriver.chrome.driver", "C://testing/chromedriver_win32/chromedriver.exe"); 
     WebDriver driver = new ChromeDriver(); 
     driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS); 
     driver.get("https://www.via.com"); 
     try { 
      driver.findElement(By.xpath("//div[@class='wzrk-button-container']/button[1]")).click(); 
     } 
     finally { 
      driver.findElement(By.xpath("//div[@class='element relElements airportElements']/input[1]")).sendKeys("BLR"); 
      driver.findElement(By.xpath("//div[@class='calendar-icon']")).click(); 
      Select s = new Select(driver.findElement(By.xpath("//*[@id='depart-cal']/div[3]"))); 
      s.selectByValue("19"); 

      driver.wait(5000); 
     } 
    } 
} 

テキストが入力されていて、カレンダーが開いていますが、日付が選択されていません。

答えて

1

ここでカレンダーは選択要素ではなく、div要素でした。したがって、この場合はselectは機能しません。コードの下

試してみてください。

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

public class ch1 { 

    static WebDriver driver; 
    public static void main(String[] args) throws InterruptedException { 
     try{ 
      System.setProperty("webdriver.chrome.driver", "C://testing/chromedriver_win32/chromedriver.exe"); 
      driver = new ChromeDriver(); 
      WebDriverWait wait = new WebDriverWait(driver,15); 
      driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS); 
      driver.get("https://www.via.com"); 
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='wzrk-button-container']/button[1]"))); 
      driver.findElement(By.xpath("//div[@class='wzrk-button-container']/button[1]")).click(); 
      driver.findElement(By.xpath("//div[@class='element relElements airportElements']/input[1]")).sendKeys("BLR"); 
      driver.findElement(By.xpath("//div[@class='calendar-icon']")).click(); 
      WebElement date = driver.findElement(By.xpath("//*[@id='depart-cal']/div[3]//div[text()='19']")); 
      wait.until(ExpectedConditions.visibilityOf(date)); 
      date.click(); 

     } 
     catch(Exception e){ 
      System.out.println(e.getMessage()); 
     } 
     finally{ 
      driver.quit(); 
     } 
    } 

} 

が、それはあなたのために働くなら、私に教えてください。

+0

ありがとうAkarsh!出来た。私は前にそれを試みた。多分私のxパスは正しくないかもしれません。 –

関連する問題