Getting Null Pointer Exception - in PageFactory in when excessing TopMenu function through testclass | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos
30% Mid August Discount Avail now

Selenium Training Forum

Getting Null Pointer Exception - in PageFactory in when excessing TopMenu function through testclass

S
suhail.itm Post on 07/02/2019

Getting Null Pointer Exception - in PageFactory in when excessing TopMenu function through testclass.

 

public class BasePage {

public WebDriver driver;
public ExtentTest test;
public TopMenu menu;

public BasePage() {}

public BasePage(WebDriver driver,ExtentTest test) {

this.driver=driver;
this.test=test;
TopMenu menu=new TopMenu(driver,test);
PageFactory.initElements(driver,menu);
}

Page Class

public class LaunchPage extends BasePage {


public LaunchPage(WebDriver driver,ExtentTest test) {

super(driver,test);

}

 

TestClass

 

launchPage.menu.logOut();

S

Instructor

Support Team Reply on 08/02/2019

In the below code:

this.test=test;
TopMenu menu=new TopMenu(driver,test);
PageFactory.initElements(driver,menu);

You have specified TopMenu again, The code needs to be like the code below.

this.test=test;
menu = new TopMenu(driver,test);
PageFactory.initElements(driver,menu);

S
suhail.itm Reply on 11/02/2019

thanks