Selenium webdriver 为什么以下代码出现空指针异常

Selenium webdriver 为什么以下代码出现空指针异常,selenium-webdriver,nullpointerexception,Selenium Webdriver,Nullpointerexception,} 我正在尝试自动化ibibo网站。我收到上面代码的nullpointer异常。我无法理解它在哪里传递空值。请帮助。谢谢你。似乎与上一篇文章的问题相同 查看@findby和@beforeclass执行顺序。进行以下更改: 替换ibibohepage home=PageFactory.initElements(driver,com.Nalini.Ibibo.ibibibohepage.class) 使用ibibohepage home=PageFactory.initElements(驱动程序,

}


我正在尝试自动化ibibo网站。我收到上面代码的nullpointer异常。我无法理解它在哪里传递空值。请帮助。谢谢你。

似乎与上一篇文章的问题相同


查看
@findby
@beforeclass
执行顺序。

进行以下更改:

  • 替换
    ibibohepage home=PageFactory.initElements(driver,com.Nalini.Ibibo.ibibibohepage.class)
  • 使用
    ibibohepage home=PageFactory.initElements(驱动程序,ibibohepage.class)

  • 您可以从
    静态WebDriver中删除
    静态
    公共类IbiboTest中

  • 公共类IbiboHomePage
    中,将WebDriver实例声明为:

  • WebDriver

  • 从构造函数
    公共IBIBOBO主页(WebDriver-driver)
    删除行
    PageFactory.initElements(driver,this)

  • 执行代码并更新状态。

    调试代码如何?@Nal我的答案解决了您的问题吗?您好,是的。非常感谢。它解决了:)是的,我已经这样做了。如果您觉得答案对您有帮助,请投票。
    public class IbiboTest {
    
    static WebDriver driver;
    
    @BeforeClass
    public void setUp() throws InterruptedException{
        System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
    
        //driver= new FirefoxDriver();
        driver.get("https://www.goibibo.com/");
        Thread.sleep(5000);
        driver.manage().window().maximize();
    
    }
    
    
    @Test
    public void testIbiboHomePage(){
        IbiboHomePage home = PageFactory.initElements(driver, com.Nalini.Ibibo.IbiboHomePage.class);
        home.clickRoundTripRadioButton();
    
    }
    
    public class IbiboHomePage {
    
    WebDriver driver;
    @FindBy(css = "input[id='gi_roundtrip_label']")
    WebElement iRoundTrip;
    
    
    public IbiboHomePage(WebDriver driver){
        this.driver = driver;
        PageFactory.initElements(driver, this);
    
    }
    
    public void clickRoundTripRadioButton(){
    iRoundTrip.click();
    }