I have 3 classes - one for page locator, one for page action and the other one as script to execute the function. am getting nullpointer exception in main scripts where the function is called. Can anyone help me out, please!!!!.
The following are the code :
- HomePageLocator.page
public class HomePageLocator{ WebDriver driver; public HomePageLocator(WebDriver driver) { this.driver= driver; }
@FindBy(xpath="//*[@id='header']/div[2]/div/div/nav/div[1]/a")
public WebElement signIn;
}
HomePageAction.page public class HomePageAction{
public WebDriver driver; public HomePageLocator homepageor;
public HomePageAction() {
this.homepage = new HomePageLocator(driver); PageFactory.initElements(driver, this.homepage);}
public void login() { homepageor.signIn.click(); }
BaseTestCase.java
public class BaseTestCase {
public static Logger log = Logger.getLogger("devpinoyLogger");
public static void main(String[] args) throws Throwable {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\Executables\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://automationpractice.com/index.php");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Home page validation
HomePageAction homepageaction= new HomePageAction();
homepageaction.login();
}
Note : Am getting exception in line (homepageaction.login();) the following is the exception logs : Exception in thread "main" java.lang.NullPointerException at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38) at com.sun.proxy.$Proxy3.click(Unknown Source) at com.way2.Pages.actions.HomePage.login(HomePageAction.java:31) at com.way2.Testcases.BaseTestCase.main(BaseTestCase.java:35)