C# 更改 selenium Webdriver 中现有的 Firefox Profile 位置



我创建了一个新的用户配置文件(In Run, type -> firefox.exe -p and create a new profile)。出于演示目的,我在桌面上创建了一个新文件夹。我的新用户配置文件指向此新位置(C:UsersusernameDesktopTemporaryProfile)。在我的硒网络驱动程序中,我想更改火狐配置文件的默认位置。

FirefoxBinary binary = new FirefoxBinary(@"C:Program Files (x86)Mozilla   Firefoxfirefox.exe");
  FirefoxProfile profile = new FirefoxProfile(@"C:UsersusernameDesktopTemporaryProfile");                                
  FirefoxDriver driver = new FirefoxDriver(binary, profile);

在上面的代码中,它没有采用新的 Firefox 配置文件位置,而是采用现有的位置。我的意思是默认位置。

FireFoxProfile类有一个名为 profileDirectory 的属性。但不幸的是,这是一个获取属性

public string ProfileDirectory { get; }

所以我无法设置目录位置。

如何在硒网络驱动程序中更改火狐配置文件位置?每当我的脚本执行时,它不应该采用默认的配置文件位置,而应该指向新的用户配置文件位置。谁能告诉我怎么做?

这对我更改配置文件很有用:

var option = new FirefoxOptions();
var profile = new FirefoxProfile("Path_to_profile");
option.Profile = profile;
IWebDriver driver = new FirefoxDriver(option);

最新更新