I have the code that is supposed to implement Page Object Model pattern using WebDriver.

package com.practice;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class Pom_Test 
    @FindBy (xpath=("//a[@href='#']/br"))
    private WebElement rgt_btn;
    private WebDriver driver;

    public  Pom_Test(WebDriver driver)
        PageFactory.initElements(driver, this);
    public void Pom_ex()
        WebDriver driver = null;
        Actions act=new Actions(driver);

However, eventually I have NullPointerException once I try to execute the code.

Exception in thread "main" java.lang.NullPointerException
at org.openqa.selenium.interactions.Actions.<init>(Actions.java:44)
at com.practice.Pom_Test.Pom_ex(Pom_Test.java:24)
at com.webdriver.Exe_Login.main(Exe_Login.java:23)

What could be the reason making the Exception to be thrown?

  • 2
    People who vote for close as "unrelated to QA" there is dozens of issues related to Webdriver/POM here. So could you comment why the case is different for this question? People who "does no understand what is being asked" could you comment what exactly you do not understand? As it seems to me the issue is in getting NPE in "act.moveToElement(rgt_btn).build().perform();"
    – Alexey R.
    Commented Jun 1, 2018 at 9:52

1 Answer 1


You start your

public void Pom_ex()


WebDriver driver = null;

which introduces a driver variable that is locally visible in your method.

Then you pass that null reference to Action and try to perform it.

What you need to do is to remove WebDriver driver = null; from your public void Pom_ex()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.