我正在尝试使用我已经为带有 selenium 2 的 firefox 设置的配置文件,但没有用于 C# 的文档。我尝试的代码如下:
FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile(profileName);
driver = new FirefoxDriver(profile);
我看到在 Java 中可比较的代码使用 ProfilesIni 而不是 FirefoxProfileManager,但在 C# 中不可用。以这种方式设置驱动程序时,使用的 selenium 配置文件具有所有默认设置,而不是我试图指向的配置文件中指定的设置。
我不确定我是否使用了正确的方法来检索配置文件,但如果有人使用过带有 C# 的 Selenium 2,任何信息都会有所帮助。
最佳答案
我们使用这种方法加载默认的 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();
}
关于c# - 在 C# 中的 Selenium WebDriver 中使用特定的 Firefox 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7615193/