6
我正在嘗試從Selenium 2升級到Selenium 3,但舊的處理方式非常簡單且快速無法工作(並且文檔看起來不存在)用Selenium 3啓動特定的Firefox配置文件
這是程序的時刻,我要的是打開Firefox驅動程序配置文件:硒
可悲的是它不工作,始終關閉與錯誤:
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: corrupt deflate stream
這是我目前的計劃:
public Program()
{
FirefoxOptions _options = new FirefoxOptions();
FirefoxProfileManager _profileIni = new FirefoxProfileManager();
FirefoxDriverService _service = FirefoxDriverService.CreateDefaultService(@"C:\Programme\IMaT\Output\Release\Bin");
_service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
try
{
if ((_options.Profile = _profileIni.GetProfile("SELENIUM")) == null)
{
Console.WriteLine("SELENIUM PROFILE NOT FOUND");
_profile.SetPreference("network.proxy.type", 0); // disable proxy
_profile = new FirefoxProfile();
}
}
catch
{
throw new Exception("Firefox needs a Profile with \"SELENIUM\"");
}
IWebDriver driver = new FirefoxDriver(_service,_options,new System.TimeSpan(0,0,30));
driver.Navigate().GoToUrl("ld-hybrid.fronius.com");
Console.Write("rtest");
}
static void Main(string[] args)
{
new Program();
}
不加載配置文件它只適用於新的FirefoxDriver(_service),但配置文件是強制性的。
硒2我使用此代碼來處理它:
FirefoxProfileManager _profileIni = new FirefoxProfileManager();
// use custom temporary profile
try { if ((_profile = _profileIni.GetProfile("SELENIUM")) == null)
{
Console.WriteLine("SELENIUM PROFILE NOT FOUND");
_profile.SetPreference("network.proxy.type", 0); // disable proxy
_profile = new FirefoxProfile();
}
}
catch
{
throw new Exception("Firefox needs a Profile with \"SELENIUM\"");
}
_profile.SetPreference("intl.accept_languages", _languageConfig);
_driver = new FirefoxDriver(_profile);
快速,簡單,但由於驅動程序不支持與服務構造和配置文件我真的不知道如何得到這個工作,任何幫助,將不勝感激
謝謝,我真的放棄了能夠使用Selenium 3 ...這樣的 - 我會說,Lowlevel Basic - 那不起作用真的很痛苦...並且任何地方對這個問題沒有任何發現甚至更多。 由於我們有多個不同的測試計算機與配置文件,但在其他位置等,我需要知道SELENIUM配置文件的路徑現在,這不是真的爲我工作的重載版本。我試過這個ProfileDirectory總是空的,它只存儲在一個非公共變量中 –
@Dominik Lemberger,每個配置文件的路徑可以通過反射訪問( )(新的FirefoxProfileManager())。GetProfile(「SELENIUM」一個'FirefoxProfileManager'實例:'var profiles =(Dictionary)manager.GetType()。GetField(「profiles」,BindingFlags.Instance | BindingFlags.NonPublic).GetValue(manager);'。 –
這在我的情況下會怎樣? FirefoxProfile配置文件=新的FirefoxProfileManager()。GetProfile(「SELENIUM」); var profile =(Dictionary)profile.GetType()。GetField(「ProfileDirectory」,BindingFlags.Instance | BindingFlags.NonPublic).GetValue(profile); options.profile = 不能使它工作(ps:以前沒有使用反射) –