有没有办法在Selenium的帮助下创建一个新的Chrome配置文件?

91zkwejq  于 2023-05-20  发布在  Go
关注(0)|答案(1)|浏览(160)

有没有办法在Selenium的帮助下创建一个新的Chrome配置文件?
有时我在尝试使用Selenium登录我的Google帐户时会收到RPC executor service threw an error!错误消息(我说的是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。

pn9klfpd

pn9klfpd1#

你可以这样做,就像下面使用Chrome选项,指定帕特到您的个人资料文件夹和新的个人资料创建

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();

您可以在下面看到使用指定配置文件

启动的chrome示例

相关问题