英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论