Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.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 Webdriver无法读取元素空指针异常。。_Java_Selenium_Webdriver - Fatal编程技术网

Java Webdriver无法读取元素空指针异常。。

Java Webdriver无法读取元素空指针异常。。,java,selenium,webdriver,Java,Selenium,Webdriver,我正在尝试自动执行登录-预订-取消的测试序列。 在预订它的罚款,但当它达到取消,它抛出一个java语言空指针Exp。 我重新检查了,我的定位器路径是正确的XPath Checker,我正在尝试获取票号并继续取消 问题是,每当WebDriver到达预订确认页面时(该页面在一段时间后加载),它就会失败并返回空指针Exp 这可能是一个正在处理的加载问题,或者我的Java概念搞砸了 请帮忙!!任何人 public class StackOverflow { public static

我正在尝试自动执行登录-预订-取消的测试序列。 在预订它的罚款,但当它达到取消,它抛出一个java语言空指针Exp。 我重新检查了,我的定位器路径是正确的XPath Checker,我正在尝试获取票号并继续取消

问题是,每当WebDriver到达预订确认页面时(该页面在一段时间后加载),它就会失败并返回空指针Exp

这可能是一个正在处理的加载问题,或者我的Java概念搞砸了

请帮忙!!任何人

public class StackOverflow { 

       public static  WebDriver driver;
       public static  Properties p;
       public static  FileInputStream f ;          

 @Test
        public void loginTest()  {
            System.out.println("Enter Login");
        Properties p=new Properties();
        FileInputStream f = null;
        try {
            f = new FileInputStream("D:\\BOSSFramework\\Framework\\locators.properties");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            p.load(f);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       

        driver = new FirefoxDriver();
        driver.get("https://in3.seatseller.travel/");
        driver.manage().window().maximize();


        try{
            driver.findElement(By.name(p.getProperty("login.username.textfield"))).sendKeys("UserName");
            driver.findElement(By.name(p.getProperty("login.password.textfield"))).sendKeys("Password");
            WebElement ele =driver.findElement(By.id(p.getProperty("login.signin.button")));
            ele.click();            
                }
             catch (Exception e) {                  
                }           
        }

@Test (dependsOnMethods={"loginTest"})
        public void booking() throws InterruptedException{
            System.out.println("Enter Booking");
            // Type Bangalore on Source Field.. 
            Properties p=new Properties();
            FileInputStream f = null;
            try {
                f = new FileInputStream("D:\\BOSSFramework\\Framework\\locators.properties");
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                p.load(f);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

                WebDriverWait wait2 = new WebDriverWait(driver, 30);
                wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(p.getProperty("oneapp.source.textfield"))));
                driver.findElement(By.xpath(p.getProperty("oneapp.source.textfield"))).sendKeys("Bangalore");
                driver.findElement(By.xpath(p.getProperty("oneapp.source.textfield"))).sendKeys(Keys.TAB);
                Thread.sleep(900L);         

                // Type Mysore on Destination Field             
                WebDriverWait wait1 = new WebDriverWait(driver, 30);
                wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath(p.getProperty("oneapp.destination.textfield"))));
                driver.findElement(By.xpath(p.getProperty("oneapp.destination.textfield"))).sendKeys("Tirupathi");
                driver.findElement(By.xpath(p.getProperty("oneapp.destination.textfield"))).sendKeys(Keys.TAB);     

  }
@Test (dependsOnMethods={"booking"})

              public void cancellation() throws InterruptedException{
                  System.out.println("Enter Cancellation");               
                    WebDriverWait wait4 = new WebDriverWait(driver, 60);
                    Thread.sleep(9000);
    /*Facing Null Pointer Exp  Here */                  
                    wait4.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(p.getProperty("oneapp.congratulations.text"))));
                    wait4.until(ExpectedConditions.presenceOfElementLocated(By.xpath(p.getProperty("oneapp.congratulations.text"))));
                    Thread.sleep(9000);
   /*Facing Null Pointer Exp  Here  */                  
                    WebElement ticket =driver.findElement(By.xpath(p.getProperty("oneapp.ticket.text")));   
   /*Want to getText() Ticket Number to cancel*/
                    String ticket1 = ticket.getText();
                    System.out.println(ticket1);
                    driver.findElement(By.xpath(p.getProperty("oneapp.leftNavCancel.link "))).click();                 
                    WebDriverWait wait1 = new WebDriverWait(driver, 30);
                    wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath(p.getProperty("oneapp.phoneNumber.textfield"))));
                    driver.findElement(By.xpath(p.getProperty("oneapp.phoneNumber.textfield"))).sendKeys(TIN1);                 
                    driver.findElement(By.xpath(p.getProperty("oneapp.search.button"))).click();
                    driver.findElement(By.xpath(p.getProperty("oneapp.cancel.button"))).click();  
}
}

在前两个方法中,创建f=newfileinputstream,但在第三个方法中,读取属性时不使用它。您是否再次尝试读取属性?

添加属性p=新属性;在您的取消方法中,或者在开始时在测试方法之外提到它,您已经声明了公共静态属性p;而是将其定义为公共静态属性p=新属性

您能提到上面代码中引发错误null指针异常的那一行吗?添加完整的StackTrace您忘记了在第三个方法中初始化p。是的,我已经编辑了所需的属性文件并将其添加到第三个方法中,它工作得很好。。。谢谢大家>>>>谢谢TDHM!它起作用了…:-