有没有办法使用Selenium来创建一个新的Chrome用户配置?

huangapple go评论56阅读模式
英文:

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

问题

Sure, here is the translation of the non-code part:

有没有办法使用Selenium创建一个新的Chrome配置文件?

有时在尝试使用Selenium登录我的Google帐户时,我会收到“RPC执行器服务抛出错误!”的错误消息(我指的是Web Google帐户,而不是Chrome帐户)。我认为这与一个Selenium测试运行中使用的配置文件有关。

因此,我想可能有一种方法可以为每个Selenium运行创建一个新的Chrome配置文件。但迄今为止我还没有找到它。

我正在使用C#,以下是我创建驱动程序的方式:

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

所以,基本上我在使用默认的sl_selenium_chrome配置文件。

null替换为任意字符串也没有帮助。即将我的代码更改为:

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

会开始在我的个人配置文件中打开Chrome。

英文:

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

得分: 1

以下是翻译好的部分:

"You can do so like below using Chrome Options, Specify the path 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"

英文:

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
有没有办法使用Selenium来创建一个新的Chrome用户配置?

huangapple
  • 本文由 发表于 2023年5月17日 23:40:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76273874.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定