Driver is null Exception

I am facing a **driver is null** exception when performing parallel testing using Selenium Grid on the LambdaTest servers. My username and access keys are correctly set, but I am unable to connect to the servers.

I downloaded the sample project from GitHub, replaced the username and access key, and ran the tests using IntelliJ IDEA. I was able to run the tests successfully. However, when I run the tests using my own configuration, I am unable to connect to the servers and receive the driver is null exception.

My project configuration is as follows:

  • Eclipse
  • Java 18
  • Selenium 4
  • TestNG 7
  • Maven
  • Running the tests using the testng.xml file

Capabilities: Browsers Firefox,Chrome,Edge,Internet Explorer

Platforms Windows 7,Windows 10,Mac os Sierra

LambdaTest Demo sample

Please provide a solution to this issue. Thank you.

Hi Nagesh,

Thanks for reaching out to us!

I would suggest you to use the configuration based on our capability generator. The link is given below

If you still face any issues, please let us know the exact capabilities that you are using in the script.

Thank you :slight_smile:

1 Like

Thanks for your reply

For individuals encountering a similar issue to mine,

Remove DesiredCapabilities instead use MutableCapabilities capabilities;

public class RemoteWebDriverExample {
    public static WebDriver driver = null;

    public static void main(String[] args) throws Exception {
        HashMap<String, Object> ltOptions = new HashMap<String, Object>();
        ltOptions.put("username", "*****************");
        ltOptions.put("accessKey", "*************************");

        MutableCapabilities capabilities = new ChromeOptions();
        ((ChromeOptions)capabilities).setCapability("LT:Options", ltOptions);

        driver = new RemoteWebDriver(new URL("url"), capabilities);

        driver.quit();
    }
}
1 Like