So I am trying to write a test in which the first step is logging in, but it is denying me access as it detected automation tools because the javascript has not been enabled and there is no profile. So I am trying to load my default profile. The problem I'm getting is that the browser does open, but it quickly fails as I get a SessionNotCreatedException. The failure occurs in the service hooks:

    public void setup() {

        "E:\\interview_notcodegod\\src\\drivers\\chromedriver.exe" );

        ChromeOptions options = new ChromeOptions();


        options.addArguments("--user-data-dir=C:/Users/[username]/AppData/Local/Google/Chrome/User Data");

        driver = new ChromeDriver(options); // intellij points here (nullpointerexception)

Is there a line of code that i'm missing? I've updated my chromedriver already because I thought that was the issue (chrome Version 99.0.4844.74 (Official Build) (64-bit), chromedriver:99.0.4844.51)

error message

2 Answers 2


In UI automation testing, it has become almost necessity to set the profiles for browsers for security reasons. So by considering this many outsourced QA testing companies are following this practice of adding chrome options and making it a mandatory coding standards in their organizations.

These options can be set using "ChromeOptions". Below is the code for setting the chrome profile :

ChromeOptions chromeProfile = new ChromeOptions();
chromeProfile.addArguments("chrome.switches", "--disable-extensions");
chromeProfile.addArguments("user-data-dir=" + chromeProfilePath);

The options.addArguments("--user-data-dir=C:/Users/[username]/AppData/Local/Google/Chrome/User Data") argument you are using to load the user profile is incorrect, you need to replace [username] with the actual username on your computer.

The error you're encountering is a SessionNotCreatedException, which indicates that the ChromeDriver failed to create a new session. Apart from the above mentioned, it can be due to various reasons other reasons, such as an incompatible version of the ChromeDriver or a mismatch between the version of Chrome and the ChromeDriver.

Here are some steps that may help resolve the issue:

  1. Check the version of Chrome and ensure that you're using a compatible version of ChromeDriver. You can find a list of supported Chrome versions in the ChromeDriver documentation.

  2. Ensure that the path to the ChromeDriver executable is correct in the System Property, as it is possible that the path is incorrect.

  3. Try creating an instance of the ChromeDriver class before setting the options and see if the issue still occurs.

If none of the above steps work, try updating the ChromeDriver to the latest version and try again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.