Home > database >  Cannot invoke "org.openqa.selenium.WebDriver.get(String)" because "driver" is nu
Cannot invoke "org.openqa.selenium.WebDriver.get(String)" because "driver" is nu

Time:06-29

I'm having a few troubles working with Selenium and the WebDriverManager. So the WebDriverManager documentations says that you're able to create a WebDriver with their API as descirbed here. Unfortunately I'm also not able to init the driver with driver = new FirefoxDriver(); since then I encounter an SessionNotCreatedException.

Code:

package test;
import io.github.bonigarcia.wdm.WebDriverManager;

public class Main {
static WebDriver driver;

public static void main(String[] args) throws InterruptedException {
  driver = WebDriverManager.firefoxdriver().create();
  driver.get("google.com");
  driver.quit();
  }
}

Exception:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.get(String)" because "driver" is null
    at test.Main.main(Main.java:9)

Setup:

  • OS: Windows 10
  • Browser: Firefox 102
  • Driver: Gecko 0.31.0
  • Selenium: 4.3.0
  • WebDriverManager: 5.2.1

CodePudding user response:

My assumption is that the driver is dead instead of using this "driver = WebDriverManager.firefoxdriver().create();" can you please try this " WebDriverManager.firefoxdriver().setup();"

CodePudding user response:

Have you tried initializing your driver like this?

 System.setProperty("webdriver.gecko.driver", 
  "src/test/resources/Driver/geckodriver.exe");
  driver = new FirefoxDriver();
  • Related