如何在Selenium C#中使用现有的Firefox配置文件?

Rav*_*ven 8 c# firefox selenium

我需要使用C#在Selenium中使用现有的Firefox配置文件.该配置文件具有我需要的已配置插件.

我发现了一些代码谷歌搜索,但那些是Java,我尝试了以下代码,但它仍然无法正常工作.

FirefoxProfile profile = new FirefoxProfile("C:\\Users\\username\\Desktop\\software\\Files");
driver = new FirefoxDriver();
Run Code Online (Sandbox Code Playgroud)

Rav*_*ven 8

我在硒的官方文件中找到了答案

var profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("Selenium");
IWebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

资料来源:Selenium docs


use*_*259 6

在新版本中可以使用此方法

1) 转到 Firefox 配置文件选择选项

在此输入图像描述

2) 创建个人资料

在此输入图像描述

FirefoxProfile profile = new FirefoxProfileManager().GetProfile("axixa");
FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;
IWebDriver firefox = new FirefoxDriver(options);
Run Code Online (Sandbox Code Playgroud)