I am starting a new Software Development project using Selenium in Java, but my code fails at the very first step: driver = new ChromeDriver();. I am receiving an error message (like "session not created" or "driver executable not found") as soon as the line executes. I have Google Chrome installed, but I’m not sure if the issue is a version mismatch, a missing system path variable, or if I need to use a manager like WebDriverManager to handle the binaries. How do I resolve this initialization failure?
3 answers
The most frequent cause of this crash in Software Development is a version mismatch. Your chromedriver.exe must match the major version of the Chrome browser installed on your machine. If your browser updated to version 121 but you are still using a driver for version 119, the session will fail to create. To fix this without manual downloads, I highly recommend using the WebDriverManager library. By adding WebDriverManager.chromedriver().setup(); right before your driver initialization, the library will automatically detect your browser version and download the correct driver for you.
I’m getting a "path to the executable must be set" error. Does this mean I have the driver but Java just can't find where I saved it on my computer?
Also, check for "Chrome for Testing." In recent Software Development updates, Google introduced a specific version of Chrome for automation that behaves slightly differently than the standard consumer browser.
I agree with Marcus. If you are using Selenium 4.11 or later, Selenium has a built-in tool called Selenium Manager that handles all of this automatically. You shouldn't even need the setProperty line anymore—just ensure your Selenium dependencies are up to date!
Julian, exactly! In Software Development, if you aren't using a manager library, you must manually tell the system where the driver is located using: System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe");. Alternatively, you can add the folder containing the driver to your Windows Environment Variables (PATH). Once the system knows where to look, that specific error should disappear and the browser should launch.