Main program
public class signin{
public static void main(String[] args) throws Exception {
util.OpenBrowser();
b.closebrowser();
}
1st method is in class util: openbrowser is one method
public class util{
public static WebDriver OpenBrowser(){
System.setProperty("webdriver.chrome.driver",
"D:\\Selenium\\selenium3.1\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
return driver;
}
2nd method(closebrowser) is in another class b
public class b {
static WebDriver driver;
public static void Execute(WebDriver driver){
homepage.phonenumber(driver).sendKeys(constant.Phonenumber);
homepage.proceedbutton(driver).click();
}
public static void closebrowser(){
driver.close();
}
}
I am trying to call 2 methods of different classes in another class and I am getting null pointer exception and pointing the line to closebroweser method. Why null pointer exception occured while calling the second method?
closebrowser method is working only when I am not calling openbrowser method from different class. It is working if i am writing openbrowser code in main program itself.