Facebook -- Login -- Null Pointer Exception | Selenium Forum
M
Posted on 20/04/2016
Hello Sir,
I was trying on my own to impliment the Page Factory Design Pattern .
I coded everything correctly. It is a basic code at Runtime it is thowing Null Pointer Exception . And i am not understanding why null pointer Exception if everything is right. I tried Debugging it but where actuall problem comes the debugger point gets navigated to Throw.class ....
Kindly see the snapshot.
Following is my code.
I have highlighted the line at which it is throwing null pointer exception.




package rough_testing_package;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;

public class FB_LoginPage {
@FindBy(xpath = ".//*[@id='email']")
public static WebElement usernameTxt;
@FindBy(xpath = ".//*[@id='pass']")
public static WebElement passwordTxt;

public static void openBrowser() {
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir") + "\\chrome\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS)
.pageLoadTimeout(30, TimeUnit.SECONDS);
driver.navigate().to("https://www.facebook.com/");
}

public static void doLogin(String username, String password) {
[b:3mq5poko]usernameTxt.sendKeys(username);[/b:3mq5poko]
passwordTxt.sendKeys(password);
passwordTxt.sendKeys(Keys.ENTER);

}

public static void main(String[] args) {
openBrowser();
doLogin("9881133347", "123456VISULON");
}
}

M
Replied on 23/04/2016

watch POM with page factory framework.

you have to create initElement() function to create the object for user name and password.


M
Replied on 25/04/2016

Sir ,
I am facing same problem again , I am automating Linkedin Login.
I am not at all understanding why is it throwing null pointer exception . In following code if i Uncomment the code [which is highlighted in green] then it works fine.
I have improvised code and imported the methods [b:31ltwhvh]initConfiguration(); initDriver();[/b:31ltwhvh] . Kindly find my code in the attachment.
package rough_testing_package;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;

import com.facebook.pages.LandingPage;
import com.facebook.pages.LoginPage;

import rough_testing_package.TestBase;

public class TestRough extends TestBase {
public static WebDriver driver;

public TestRough(WebDriver dr) {
driver = dr;
}

public static void main(String[] args) throws InterruptedException {

[b:31ltwhvh]initConfiguration();
initDriver();[/b:31ltwhvh]


/* [color=#004000:31ltwhvh] System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir") + "\\chrome\\chromedriver.exe");
driver = new ChromeDriver(); driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS)
.pageLoadTimeout(30, TimeUnit.SECONDS);
driver.navigate().to("https://in.linkedin.com/");[/color:31ltwhvh]

*/
LoginPage lp = PageFactory.initElements(driver, LoginPage.class);
LandingPage landing = lp.doLogin("",
"");
landing.verifyLinkedinLogo();
}

}


M
Replied on 26/04/2016

don't give txt file zip and upload your entire project.


M
Replied on 26/04/2016

I have mailed my project on
[b:27sg5hq0]its.thakur@gmail.com[/b:27sg5hq0] and[b:27sg5hq0] info@qtpselenium.com [/b:27sg5hq0]
Because i am unable to attach my project in the attachment on the Board.

Kindly use following classes,
[b:27sg5hq0]TestClass.Java[rough_testing_package],
LoginPage.java[com.facebook.pages],
LandingPage.java[com.facebook.pages],
TopMenu.java[com.facebook.pages],
Constants.java[com.facebook.util].[/b:27sg5hq0]

I have automated Linkedin Webpages.


M
Replied on 27/04/2016

what is your email id?


M
Replied on 27/04/2016

atulpatil33347@hotmial.com


M
Replied on 28/04/2016

we didn't get the full project only 3 txt files. please provide us your full project so we can assist you.


M
Replied on 29/04/2016

Sir,
I have already mailed the project on

[b:2g02e1gb]its.thakur@gmail.com and info@qtpselenium.com [/b:2g02e1gb]

My mail id is atulpatil33347@hotmail.com.
i rechecked my mail just now. I have sent project on the mail.


M
Replied on 29/04/2016

i checked there is nothing. posted it here.


M
Replied on 01/05/2016

ok,
i have sent my project on skype account of trainer-Ashish Thakur.


M
Replied on 02/05/2016

found the problem
[quote:3gbdq0g0]
initDriver();[/quote:3gbdq0g0]
this method is not initializing the driver from logintest.java but it making a new webdriver object in testbase.java and initialing driver in it.


M
Replied on 02/05/2016

so how can i solve this issue ?
and use the driver which is initialized in TestBase.java


M
Replied on 03/05/2016

initiate driver in Testbase.java class constructor and then extend that class all the tests. and use the extended driver.