硒在C#中使用特定的Firefox配置文件2的webdriver [英] Using a specific firefox profile in selenium 2 webdriver in C#
问题描述
我试图用我已经建立了火狐硒2的配置文件,但没有对C#的文档。我试图代码如下:
I am trying to use a profile I already have set up for firefox with selenium 2 but there is no documentation for C#. The code I have attempted is as follows:
FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile(profileName);
driver = new FirefoxDriver(profile);
这是我所看到的
代码是comparible在Java中使用ProfilesIni代替FirefoxProfileManager,但不可用在C#。当以这种方式设置驱动程序使用的硒配置文件具有所有的默认设置,而不是在配置文件中我试图指向指定的设置。
Code that I have seen that is comparible in Java uses ProfilesIni instead of FirefoxProfileManager, but that is not available in C#. When setting up the driver in this way the selenium profile used has all the default settings instead of the settings specified in the profile I am trying to point to.
我不确定我使用了正确的方法来获取配置文件,但如果有人使用了硒2 C#中,所有信息将是有益的。
I am not sure that I am using the correct methods to retrieve the profile, but if anyone has used Selenium 2 with C#, any information would be helpful.
推荐答案
我们用这样的方法来加载默认的Firefox配置文件(你可以创建自定义配置文件并加载它):
We use such method to load default firefox profile (you can create custom profile and load it):
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#中使用特定的Firefox配置文件2的webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!