FindBy in pageFactory (webdriver) doesn't work correctly
<p>I want to write tests in selenium <code>WebDriver</code> with <code>PageFactory</code>, but if I add annotations in <code>PageFactory</code> form in class</p>

<pre><code>@FindBy(id="email")
public WebElement mailLink;
</code></pre>

<p>and usage:</p>

<pre><code>mailLink.sendKeys("mail@mail.com");
</code></pre>

<p>I get a <code>NullPointerException</code> every time. Another way:</p>

<pre><code>driver.findElement(By.id("email")).sendKeys("mail@mail.com");
</code></pre>

<p>returns correct value. Where is the problem with first method?</p>

<p>My code:</p>

<p>I have got driver initialization in FaceClass:</p>

<pre><code>public class FaceClass {

protected WebDriver driver;

public FaceClass(WebDriver driver){
    this.driver = driver;
}

public HomePage navigateToApp(){
    driver.navigate().to("https://facebook.pl");

    return PageFactory.initElements(driver, HomePage.class);
}
</code></pre>

<p>}</p>

<p>and class with business logic:</p>

<pre><code>public class HomePage extends FaceClass{

public HomePage(WebDriver driver) {
    super(driver);
    // TODO Auto-generated constructor stub
}


@FindBy(id="email")
public WebElement mailLink;

@FindBy(id="pass")
public WebElement passLink;

@FindBy(how = How.ID, using="u_0_n")
public WebElement loginButton;


public ProfilePage navigateToProfile(){

    try{

        if(driver.findElement(By.id("pass")).isEnabled() || driver.findElement(By.id("pass")).isDisplayed()){
            System.out.println("ok!");
        }



    //driver.findElement(By.id("pass")).sendKeys("pass_to_account");
    //driver.findElement(By.id("email")).sendKeys("mail@mail.com");
    //driver.findElement(By.id("u_0_n")).click();
    mailLink.sendKeys("mail@mail.com");
    passLink.sendKeys("pass_to_account");
    loginButton.click();

    } catch (Exception e) {
        e.printStackTrace();
        }

    return PageFactory.initElements(driver, ProfilePage.class);
}
</code></pre>

<p>}</p>

<p>and test:</p>

<pre><code>    public class ExampleTest {

WebDriver driver;

@Before
public void setUp() throws Exception {

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    DesiredCapabilities capabilities=DesiredCapabilities.chrome();
    capabilities.setCapability("marionette", true);
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.navigate().to("https://facebook.pl");
}

@After
public void tearDown() throws Exception {

    driver.quit();
}

@Test
public void test() {
    //fail("Not yet implemented");
    HomePage homepage = new HomePage(driver);
    homepage.navigateToProfile();

}
</code></pre>

<p>}</p>

<p>All elements are enabled and visible</p>