2017-07-12 13 views
-1

こんにちは私はこのコードを書いています。今のところ日付部分は期待どおりに動作しますが、時間部分では例外もなくタイムスロットも表示されません。セレニウム処理Javaでリスト

URL: - https://www.dineout.co.in/delhi/boa-village-civil-lines-north-delhi-21335

WebDriver driver; 
String datee=""; 
String t=""; 

public RDP(WebDriver ldriver){ 
    this.driver=ldriver; 
} 


@FindBy(how=How.XPATH,using="//input[@class='form-control']") 
WebElement Time_selector; 

@FindBy(how=How.XPATH,using="//*[@class='do do-calender-icon']") 
WebElement calender; 
public void logged_in_user_booking() throws InterruptedException 
{ 
    calender.click(); 
    Thread.sleep(4000); 
    List<WebElement> dates= driver.findElements(By.cssSelector("ul.days li")); 

    //System.out.println(dates); 
    for(int i=0 ;i<dates.size();i++) 
    { 
     datee = dates.get(i).getText(); 
     if(datee.equalsIgnoreCase("31")) 
     { 

      dates.get(i).click(); 
      break; 
     } 

    } 

    List<WebElement> time_slots = driver.findElements(By.cssSelector("div.timings-wrap ul li")); 
    for(int j=0 ;j<time_slots.size();j++) 
    { 
     t = time_slots.get(j).getText(); 
     System.out.println(t); 

    /* if(t.equalsIgnoreCase("03:00 pm")) 
     { 

      time_slots.get(j).click(); 
      break; 
     } 
     */ 

} 
+0

あなたの質問は何であると明示的な待機を使用することができますか? – DCON

答えて

0

あなたがimplicitlyWaitdriver.findElementsを設定していないので、もしスロットは、ロードに時間がかかる時間が存在する任意の要素を待たないであろうと、空のリストを返します。 driverインスタンシエーションの直後にimplicitlyWaitを追加すると、この問題が解決するはずです(とにかく追加する必要があります)。

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 

またExpected Conditions

WebDriverWait wait = new WebDriverWait(driver, 10); 
List<WebElement> time_slots = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("div.timings-wrap ul li"))); 
関連する問題