首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firepath显示匹配的节点,但不打印

Firepath显示匹配的节点,但不打印
EN

Stack Overflow用户
提问于 2017-04-16 03:14:48
回答 1查看 32关注 0票数 0

我正试图把价格记录在一个清单上,然后打印出来。但是,执行会在“搜索结果”页面中停止,并且不会打印价格。我认为这是因为Xpath的级别(可能我不是从上层选择?)。我很困惑,因为我已经创建了Xpath,当我在Firepath中使用这个Xpath时,它会选择39个匹配的节点。

提前感谢您的时间和建议。

代码:

代码语言:javascript
复制
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();

    }
}

问题:不印价格。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-16 08:11:36

您正面临此问题,因为尚未加载所有结果,因此必须等待所有搜索结果加载,因此需要等待搜索结果进度栏达到100%,如下所示:

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

代码语言:javascript
复制
    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());
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43433342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档