在C#中使用Selenium WebDriver中的特定Firefox配置文件

Jef*_*ald 12 c# firefox selenium webdriver

我正在尝试使用我已经使用selenium 2为firefox设置的配置文件但是没有C#的文档.我试过的代码如下:

FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile(profileName);
driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

我在Java中看到的代码使用的是使用ProfilesIni而不是FirefoxProfileManager的代码,但这在C#中不可用.以这种方式设置驱动程序时,使用的selenium配置文件具有所有默认设置,而不是我试图指向的配置文件中指定的设置.

我不确定我是否使用正确的方法来检索配置文件,但如果有人使用Selenium 2和C#,任何信息都会有所帮助.

the*_*zar 6

我们使用这种方法加载默认的firefox配置文件(您可以创建自定义配置文件并加载它):

private IWebDriver driver;  
string pathToCurrentUserProfiles = Environment.ExpandEnvironmentVariables("%APPDATA%") + @"\Mozilla\Firefox\Profiles"; // Path to profile
string[] pathsToProfiles = Directory.GetDirectories(pathToCurrentUserProfiles, "*.default", SearchOption.TopDirectoryOnly);
if (pathsToProfiles.Length != 0)
{
     FirefoxProfile profile = new FirefoxProfile(pathsToProfiles[0]);
     profile.SetPreference("browser.tabs.loadInBackground", false); // set preferences you need
     driver = new FirefoxDriver(new FirefoxBinary(), profile, serverTimeout);
}
else
{
     driver = new FirefoxDriver();
}
Run Code Online (Sandbox Code Playgroud)


Bri*_*212 0

我有同样的问题,它不是重复的。

我正在使用以下有效的

private IWebDriver Driver;

[Setup]
public void SetupTest()
{
string path = @"C:\Users\username\AppData\Local\Mozilla\Firefox\Profiles\myi5go1k.default";
FirefoxProfile ffprofile = new FirefoxProfile(path);
Driver = new FirefoxDriver(ffprofile);
}
Run Code Online (Sandbox Code Playgroud)