0

I'm trying to learn the framework structure of Selenium with Page Object model framework. Even though I pass the webdriver instance, I'm getting NullPointerException when trying to access a textbox element which I'm referred from POM file. I'm trying to launch a page and entering text in the textbox. testBase.java for launching Chrome browser

package TestBase;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class testBase {
    public static WebDriver driver;
    public static WebDriver initDriver()
    {
        System.setProperty("webdriver.chrome.driver", "C:/Users/edksuresh/Downloads/chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        return driver;
    }
}

'Object repository file'

package pom;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class POM_LoginPage {
    public WebDriver driver;
    @FindBy(xpath="//input[@id='email']")
    public WebElement uid;
    public POM_LoginPage(WebDriver wd)
    {
        this.driver = wd;
    }
}

Registration.java

package generalComponent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import TestBase.testBase;
import pom.POM_LoginPage;

public class Registration {
    WebDriver driver;
    String url;
    POM_LoginPage pomLogin;
    public Registration(WebDriver wd)
    {
        this.driver = wd;
    }
    public void launchPage()
    {
        driver = testBase.initDriver();
        pomLogin = new POM_LoginPage(driver);
        url = "http://demo.automationtesting.in/";
        driver.get(url);
        pomLogin.uid.sendKeys("sss@gg.com");
    }
}

NullPointerException is thrown at line pomLogin.uid.sendKeys("sss@gm.com").

1 Answers1

0

please update the object repository file with the below code. The thing is that you have forgotten to call initElements method of pagefactory.

 public POM_LoginPage(WebDriver wd)

    {
        this.driver = wd;
        PageFactory.initElements(driver,this)
    }
UnknownBeast
  • 979
  • 1
  • 6
  • 13