package base;
import java.util.concurrent.TimeUnit;
public class Page{
public static WebDriver driver;
public Page() {
if(driver==null) {
WebDriverManager.chromedriver().setup();
driver.get("https://www.zoho.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
}
Asked
Active
Viewed 861 times
0

Mark Rotteveel
- 100,966
- 191
- 140
- 197

vaishnavi A.N.
- 11
- 4
-
2`driver` is still `null` by the time you are calling `driver.get()`. You need to initialize it to an actual `WebDriver` object. – Dev Yego Jul 19 '20 at 07:07
1 Answers
0
The driver
inside if(driver == null){..}
will ofcourse be null and when you are trying to do driver.get("https://www.zoho.com/");
you are getting NPE.
You have forgot to assign to the driver
variable.
if(driver==null) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://www.zoho.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

Abhinaba Chakraborty
- 3,488
- 2
- 16
- 37
-
Actually now i have given if(driver==null),even before giving that,i got the NPE @ driver.get("https://www.zoho.com/"); – vaishnavi A.N. Jul 19 '20 at 07:13
-
So are your still getting NPE with this code? If so, then webdrivermanager is not finding the installed chrome installed in your system. – Abhinaba Chakraborty Jul 19 '20 at 07:15
-
I have assigned the ChromeDriver to the driver variable,right?is it not assigned? – vaishnavi A.N. Jul 19 '20 at 07:19
-
No, This line `WebDriverManager.chromedriver().setup()` doesnt assign the driver variable. Please check my code. – Abhinaba Chakraborty Jul 19 '20 at 07:27
-
-
yeah perfect ! Thank you very much @Abhinaba Chakraborty, I was thinking what was going wrong with my code,Thank you again... – vaishnavi A.N. Jul 19 '20 at 09:26