2017-04-16 5 views
0

私はリスト内の価格を取得して印刷しようとしています。ただし、実行結果は検索結果ページで停止し、価格は印刷されません。私はそれがXpathのレベルのためだと思う(おそらく私は上のレベルから選んでいない?)。私はXpathが作成したので、混乱しています。Firepathでそれを使用すると、39個の一致するノードが選択されます。Firepathに一致するノードが表示されますが、印刷されません。

時間とアドバイスをありがとうございます。

コード:

import java.util.List; 


import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class Flight { 

    public static WebDriver driver; 

    //This following section is for browser and getting the url 
    public static WebDriver browser(){ 

     driver= new FirefoxDriver(); 

     driver.get("https://www.orbitz.com/Flights"); 
     return driver; 

    } 

    //this following section is getting the properties of the page  
    public static void getPageProperties(String ff,String ft, String fd, String rd){ 

     WebElement flyFrom= driver.findElement(By.id("flight-origin")); 
     WebElement flyTo= driver.findElement(By.id("flight-destination")); 
     WebElement flyDate= driver.findElement(By.id("flight-departing")); 
     WebElement returnDate= driver.findElement(By.id("flight-returning")); 
     WebElement flight_search_btn= driver.findElement(By.id("search-button")); 

     flyFrom.sendKeys(ff); 
     flyTo.sendKeys(ft); 
     flyDate.sendKeys(fd); 
     returnDate.sendKeys(rd); 
     flight_search_btn.click(); 

    } 

    // this following section will have the arguments that we will provide for flight search 
    public static void testFligthSearch(){ 

     Flight f= new Flight(); 
     f.browser(); 
     f.getPageProperties("MSP", "SEA", "05/01/2017", "05/05/2017"); 

     List<WebElement> pricelist= driver.findElements(By.xpath("//span[contains(@class,'dollars')]")); 

     for(WebElement e: pricelist){ 

      System.out.println("The prices are: " + e.getText()); 
     } 

    } 

    public static void main (String [] args){ 

     Flight f= new Flight(); 
     f.testFligthSearch(); 

    } 
} 

問題:価格は印刷されません。

答えて

0

すべての結果がまだロードされていないため、すべての検索結果が読み込まれるまで待つ必要があるため、次のように検索結果の進行状況バーが100%になるまで待つ必要があるため、この問題が発生します。

WebElement progressBar = driver.findElement(By.cssSelector( "#acol-interstitial> div> div"));

WebDriverWait wait = new WebDriverWait(driver, 20); 
    wait.until(ExpectedConditions.attributeContains(progressBar, "style", "width: 100%;")); 

    List<WebElement> pricelist= driver.findElements(By.cssSelector("ul#flightModuleList div.offer-price.urgent > span.visuallyhidden")); 

    for(WebElement e: pricelist){ 

     System.out.println("The prices are: " + e.getText()); 
    } 
関連する問題