Getting driver as null | Selenium Forum
M
Posted on 25/08/2015
i am getting null pointer exception.
i have define isElementPresent() in TestBase.java and i am calling this function in Test.java with TestBase Class object. but when control passing to isElementPresent() function then here i am getting null in driver. i debug this and check driver value in debug mode and getting null.
i am attaching screen shot of both classes.
Please suggest

M
Replied on 25/08/2015

attaching TestBase.java

Responsive image

M
Replied on 26/08/2015

what is happening is on line 174 of testbase your program is giving an exception null pointer.

basically means is that you have no driver.findelement is not working

reasons probably because it can't read the file
or
because it can't find the element and hence no size could be given
or
some other reason but first check these 2 first.


M
Replied on 26/08/2015

basically what happening that both classes in different packages and when i create object of TestBase and calling its function then driver not initializing. so i want to know what i do. when i debug driver getting null.


M
Replied on 26/08/2015

You have declared driver object locally
You need to declare it globally


M
Replied on 26/08/2015

i have declared globally in TestBase like this.
public WebDriver driver;


M
Replied on 26/08/2015

calling its function then driver not initializing.

you have to watch the entire framework module 20

but the main point is driver has to be initialized in testbase with "Public static Webdriver=null;"
and in a function you can start Firefox, Chrome, IE etc.
and then you would have to make different functions for opening a website, basically anything.