user3782636
user3782636

Reputation: 83

java.lang.NullPointerException at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)

I'm new to selenium framework, i am trying to create a framework and started my steps towards learning framework. I have written a code for login page but here i'm getting "nullPointerException". Anyone's help would be better. Thanks in advance. enter image description hereenter image description here

Upvotes: 0

Views: 13617

Answers (4)

Usman Kokab
Usman Kokab

Reputation: 193

I was also facing the same problem. As I am using BaseClass (parent class) for my tests where I declared WebDrive driver and mistakenly I also declared Webdriver in my test class (child class). It was making a duplicated declaration of the driver. Just removing, WebDriver driver; from child class, this issue resolved

Upvotes: 0

Vikash Kumar
Vikash Kumar

Reputation: 11

Better place the editable code so that it can get rectified; 1. Remove static from static webdriver driver in Utility 2. Remove webdriver declared in Login page

Question: Does base url launches homepag or signin page If home page then 1. Create a home page class 2. In utility- make this asignment --
Homepage homepgobj = driver.get(url) ;
return homepgobj;
and replace void with text Homepage. 3. Now in Homepage Create method to navigate to Login page using pagefactory In
public LogInPage navigateToLoginPage(){
driver.navigate().to("Loginpage url");
LoginPage logInPageObj = PageFactory.initElements(driver, LoginPage.class);
return loginPageObj; } 4. On homepage create const. to driverobj just like done in login page but do not place pagefactory in it 5. Also remove page factory element from const. of Signin page 6. Create login page test class to write tests . Now while writin test navigate to signin page like this Homepage homepgObj = startBrowser(browser, url) --
--this will navigate to homepage
Login loginpgObj = homepgObj.callmethodcreatedinhomepage] --
-- will navigate to signin page.

 loginpgObj.[Call methods of loginpg]

Upvotes: 0

Vinayak
Vinayak

Reputation: 439

This is because of Declaring the WebDriver driver; in both parent class and child class.

Example : 1.created one base class and in base class declaring the Webdrievr; 2.Created child class and declare the webdriver in child class. 3.child class extends base class. this issue comes.

So declare the WebDriver driver in either Base class or Child Class.

Upvotes: 0

Monis Majeed
Monis Majeed

Reputation: 1378

Your driver is not initialised ,for which the code you have written in Utility Class, you can extend UtlitlityClass in your LoginPage and use @BeforeMefthod in LoginPage where you can create an instance of driver and use it in your test method and @AfterMethod to destroy the same.

Upvotes: 1

Related Questions