Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Firepath显示匹配的节点,但不打印_Java_Selenium - Fatal编程技术网

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

Java Firepath显示匹配的节点,但不打印,java,selenium,Java,Selenium,我正试图把价格记录在一个列表中并打印出来。但是,执行会在搜索结果页面中停止,并且不会打印价格。我认为这是因为Xpath的级别(可能我不是从更高的级别中选择?)。我很困惑,因为我创建的Xpath在Firepath中使用时选择了39个匹配节点 提前感谢您的时间和建议 代码: import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.se

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

提前感谢您的时间和建议

代码:

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();

    }
}
import java.util.List;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.firefox.FirefoxDriver;
公务舱航班{
公共静态WebDriver;
//以下部分用于浏览器和获取url
公共静态WebDriver浏览器(){
驱动程序=新的FirefoxDriver();
驱动程序。获取(“https://www.orbitz.com/Flights");
返回驱动器;
}
//以下部分将获取页面的属性
公共静态void getPageProperties(字符串ff、字符串ft、字符串fd、字符串rd){
WebElement flyFrom=driver.findElement(By.id(“航班来源”);
WebElement flyTo=driver.findElement(By.id(“航班目的地”);
WebElement flyDate=driver.findElement(By.id(“航班出发”);
WebElement returnDate=driver.findElement(By.id(“航班返回”);
WebElement flight\u search\u btn=driver.findElement(By.id(“搜索按钮”));
flyFrom.sendKeys(ff);
flyTo.sendKeys(英尺);
flyDate.sendKeys(fd);
返回日期。发送键(rd);
航班搜索点击();
}
//以下部分将提供我们将为航班搜索提供的参数
公共静态void testflightsearch(){
航班f=新航班();
f、 浏览器();
f、 getPageProperties(“MSP”、“SEA”、“2017年1月5日”、“2017年5月5日”);
List pricelist=driver.findElements(By.xpath(//span[contains(@class,'$s')]);
对于(WebElement e:价格表){
println(“价格为:+e.getText());
}
}
公共静态void main(字符串[]args){
航班f=新航班();
f、 testFligthSearch();
}
}

问题:未打印价格。

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

WebElement progressBar=driver.findElement(By.cssSelector(“#acol interstitual>div>div”)

WebDriverWait wait=newwebdriverwait(驱动程序,20);
wait.until(ExpectedConditions.attributeContains(progressBar,“样式”,“宽度:100%;”));
List pricelist=driver.findElements(By.cssSelector(“ul#flightModuleList div.offer-price.urgent>span.visuallyhidden”);
对于(WebElement e:价格表){
println(“价格为:+e.getText());
}
    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());
    }