0

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
jxmhsrgg
  • 1
  • 2
  • seems like you're missing Selenium itself... and the import of: import org.openqa.selenium.WebDriver; – pcalkins Jun 28 '22 at 17:41

3 Answers3

0

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

Bâlà
  • 51
  • 3
0

Have you tried initializing your driver like this?

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

In Import, instead of TestNG annotations you may be given JUnit.

Before :

import org.junit.AfterClass;

After :

import org.testng.annotations.AfterClass;
Ryan M
  • 18,333
  • 31
  • 67
  • 74