Is there a way to create a new Chrome profile with the help of Selenium?

175 Views Asked by At

Is there a way to create a new Chrome profile with the help of Selenium?

Sometimes I am getting the RPC executor service threw an error! error message while trying to log into my Google account using Selenium (I am talking about the web Google account, not the account for the Chrome). I think it is related to the profile being used for more than one Selenium test run.

So, I thought that there may be a way to create a new Chrome profile for every Selenium run. I was not able to find it so far though.

I am using C# and here is how I am creating my driver:

var driver = UndetectedChromeDriver.Instance(null, chromeOptions);.

So, basically I am using the default sl_selenium_chrome profile.

Specifying the arbitrary string instead of the null did not help. I.e. changing my code to the:

var driver = UndetectedChromeDriver.Instance(Guid.NewGuid(), chromeOptions);

started to open Chrome in my personal profile.

1

There are 1 best solutions below

0
Abhay Chaudhary On BEST ANSWER

You can do so like below using Chrome Options, Specify the pat to your Profiles Folder and the New Profile to Create

        ChromeOptions options = new ChromeOptions();
        String profileDir="Profile_Test_1";
        // Specify the path to the new profile directory
        options.AddArgument("--profile-directory="+profileDir);
        options.AddArgument("--user-data-dir=/Users/achaudhary/Desktop/chromeProfiles/CustomProfile");

        // Instantiate ChromeDriver with the options
        IWebDriver driver = new ChromeDriver(options);

        // Rest of your code...

        // Quit the driver
        driver.Quit();

You can see below chrome instance launched with the specified profile enter image description here