RE: java.lang.NullPointerException


Newbie here and I am getting java.lang.NullPointerException for the simple test below, out of ideas now. I have shown the stack trace error below and also both of my pages and my test lastly. Any help or advice greatly appreciated!

at mytestpack.A_Login.test(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.InvokeMethod.evaluate(
at org.junit.runners.ParentRunner.runLeaf(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

package mypagespack;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class A_LoginPage {

final WebDriver driver;

//Identify Username inputbox
@FindBy(id = “UserName”)
WebElement username;

//Identify Password inputbox
@FindBy(id = “Password”)
WebElement password;

//Identify logo – Potentially requires form after body
@FindBy(xpath = “/html/body/div[3]/div/img”)
WebElement logo;

//Identify Login button
@FindBy(id = “butLogin”)
WebElement loginbutton;

//Identify Lower logo
@FindBy(xpath = “/html/body/div[6]/div/div[1]/img”)
WebElement lowerlogo;

//Identify email address link
@FindBy(xpath = “/html/body/div[6]/div/div[2]/a”)
WebElement emaillink;

//Identify support text
@FindBy(xpath = “/html/body/div[6]/div/div[2]/text()[1]”)
WebElement loginsupport;

//Intialise elements
public A__LoginPage(WebDriver driver) {
this.driver = driver;

//Method to add username and password arguments
public void loginTo(String strusername, String strPassword){

//Fill user name

//Fill password

//Click Login button;

package mypagespack;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class B_HomePage {

final WebDriver driver;

//Identify Logout button
@FindBy (xpath = “/html/body/div/div[2]/div[1]/a/img”)
public WebElement logout;

//Identify the logged in user
@FindBy (xpath = “/html/body/div/div[2]/div[2]/span[1]”)
public WebElement loggedinuser;

//Initialise elements
public B_HomePage(WebDriver driver) {
this.driver = driver;

package mytestpack;

import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import mypagespack.B_HomePage;
import mypagespack.A_LoginPage;

public class A_Login {
static WebDriver driver;
A_LoginPage LoginPage;
B_HomePage HomePage;


public void beforeMethod(){
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

HomePage = PageFactory.initElements(driver, B_HomePage.class);

LoginPage = PageFactory.initElements(driver, A_LoginPage.class);

public void test(){


System.out.println(“Login Successfully Completed”);;


public void afterMethod(){


Add Comment
2 Answers

Check if this is causing problem name of the class is wrong

//Intialise elements
public A__LoginPage(WebDriver driver) {

as i can se there are A__ (underscore twice) @stevie24xx

Default Answered on May 7, 2016.

That must have been a typo here as it is a single underscore in my code, I edited the names slightly for privacy purposes – Thanks for the suggestion though 🙂

on May 9, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.