NullpointerException while invoking SendKeys through Selenium using PageFactory with Page Object

后端 未结 2 2023
醉梦人生
醉梦人生 2020-12-12 05:02

I have three classes. One for getting all elements from the Webpage, one for performing actions with those elements and one for the test scripts. I get a null pointer except

2条回答
  •  一向
    一向 (楼主)
    2020-12-12 05:49

    You can continue to use the @FindBy annotations you just need to make sure you initialise the WebElements. To do this you should initialise your LoginPageElements using PageFactory:

    LoginPageElements loginPageElements = PageFactory.initElements(webDriver, LoginPageElements.class);
    

    where webDriver is an instance of the WebDriver you are using to run the selenium tests.

提交回复
热议问题