Selenium webdriver java.lang.NullPointerException:无法调用;org.openqa.selenium.WebDriver.findelelement(org.openqa.selenium.By)“;因为";“这个司机”;是空的

Selenium webdriver java.lang.NullPointerException:无法调用;org.openqa.selenium.WebDriver.findelelement(org.openqa.selenium.By)“;因为";“这个司机”;是空的,selenium-webdriver,junit4,cucumber-junit,Selenium Webdriver,Junit4,Cucumber Junit,我也尝试了隐式等待时间,但它不起作用。请帮我解决这个错误 我在JUnit失败跟踪中收到此错误 java.lang.NullPointerException:无法调用“org.openqa.selenium.WebDriver.manage()”,因为“this.driver”为空 在stepdefs.CrmStepdefs.user上单击了日历选项,并且月表可见(CrmStepdefs.java:54) 在✽.用户单击日历选项,月表可见(文件:src/test/resources/featur

我也尝试了隐式等待时间,但它不起作用。请帮我解决这个错误


我在JUnit失败跟踪中收到此错误

java.lang.NullPointerException:无法调用“org.openqa.selenium.WebDriver.manage()”,因为“this.driver”为空
在stepdefs.CrmStepdefs.user上单击了日历选项,并且月表可见(CrmStepdefs.java:54)
在✽.用户单击日历选项,月表可见(文件:src/test/resources/features/CreateEvent.feature:10)

这是否回答了您的问题?
package stepdefs;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class CrmStepdefs
{
    WebDriver driver;
    
    @Given("User navigate to the login page")
    public void user_navigate_to_the_login_page()
    {
        System.setProperty("webdriver.chrome.driver", "F:\\webdriv\\chromedriver.exe");             
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--remote-debugging-port=9222");
        chromeOptions.addArguments("--no-sandbox");

        this.driver = new ChromeDriver(chromeOptions);                                  //setup chrome driver before every method
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        
        driver.get("https://freecrm.com/index.html");
    }

    @When("User enters Email id And password")
    public void user_enters_Email_id_And_password() 
    {
        driver.findElement(By.cssSelector(".icon-xs")).click();
        driver.findElement(By.name("email")).sendKeys("xyz@gmail.com");
        driver.findElement(By.name("password")).sendKeys("ik@10");
    }

    @Then("User should on home page")
    public void user_should_Login_And_on_home_page()
    {
        driver.findElement(By.cssSelector(".fluid")).click();

        driver.findElement(By.xpath("//*[@id=\"main-nav\"]/div[2]/a/span")).click(); 
    }

    above statement should execute here
    @Then("User clicked on calendar option and month table is visible")
    public void user_clicked_on_calendar_option_and_month_table_is_visible()
    {
        driver.findElement(By.xpath("//*[@id=\"main-nav\"]/div[2]/a/span")).click(); 
    }   
}