title: NullPointerException when running my test with page factory
body: <p>I get an exception when I run my test. I am using selenium with page factory. When I run following code ,it will open up the website and fail with exception below. it doesn't perform the <code>HomePage.ClickbtnCookieWarning()</code> in my test case.</p>
  
  <p>Can someone please help me to understand why my code isn't working?</p>
  
  <blockquote>
    <p>FAILED CONFIGURATION: @BeforeTest SetUp 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.$Proxy5.click(Unknown Source)  at
    pageObjects.HomePage.ClickLoginLink(HomePage.java:57)     at
    myaccountsuite.TC1DefaultDeliveryAddDisplay.SetUp(TC1DefaultDeliveryAddDisplay.java:29)</p>
  </blockquote>
  
  <p>Home Page page object </p>
  
  <pre><code>public class HomePage {
  
      WebDriver driver;
  
      public HomePage (WebDriver driver)
      {
          this.driver=driver;         
      }
  
      @FindBy(id="ctl00_header_hdrCookieWarning_btnHideCookieWarning")
      WebElement btnCookieWarning;
  
      @FindBy(xpath=".//*@id='ctl00_masterContainerTop_Block_637_LoginView1_ulAnonymous']/li[2]/a")
      WebElement LoginLink;
  
      public void ClickbtnCookieWarning()
      {
          btnCookieWarning.click();
      }
  
      public void ClickLoginLink()
      {
          LoginLink.click();
      }
  }
  </code></pre>
  
  <p>Login Page Object </p>
  
  <pre><code>public class login {
  
      WebDriver driver;
  
      public login(WebDriver driver)
      {
          this.driver = driver; 
      } 
  
      @FindBy(id="ctl00_ContentPlaceHolderMain_container_container_Block_166_lgn1_UserName")
      WebElement UserName;
  
      @FindBy(id="ctl00_ContentPlaceHolderMain_container_container_Block_166_lgn1_Password")
      WebElement Password;
  
      @FindBy(id="ctl00_ContentPlaceHolderMain_container_container_Block_166_lgn1_LoginButton")
      WebElement btn_LogIn;
  
      @FindBy(id="ctl00_ContentPlaceHolderMain_container_container_Block_166_lgn1_txtAccount")
      WebElement Account;
  
      @FindBy(id="ctl00_ContentPlaceHolderMain_container_container_Block_166_lgn1_btnHomeBranch_3")
      WebElement btn_Continue;
  
      public void userLogin(String uname, String pass, String acc) 
      {
          UserName.sendKeys(uname);
          Password.sendKeys(pass);
          btn_LogIn.click();
          driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
          Account.sendKeys(acc);
          btn_LogIn.click();
          btn_Continue.click();
      }     
  }
  </code></pre>
  
  <p>My Test</p>
  
  <pre><code>public class TC1DefaultDeliveryAddDisplay {
      public WebDriver driver;
  
      @BeforeTest(alwaysRun = true)
      public void SetUp() {
  
          HomePage HomePage = PageFactory.initElements(driver, HomePage.class);
          login loginpage = PageFactory.initElements(driver, login.class);
  
          driver = new FirefoxDriver();
          driver.get("http://URL/");
          HomePage.ClickbtnCookieWarning();
          HomePage.ClickLoginLink();
          loginpage.userLogin("aa@yahoo.com", "125", "Test");
  
      }
  </code></pre>