【问题标题】:Unable to instantiate Marionette driver with both a FirefoxProfile & FirefoxDriverService无法同时使用 FirefoxProfile 和 FirefoxDriverService 实例化 Marionette 驱动程序
【发布时间】:2017-02-14 22:18:16
【问题描述】:

我目前正在使用适用于 Firefox 的新 Marionette 驱动程序更新我的 C# 解决方案。

我已经设法让驱动程序使用以下代码成功启动一个 url

        FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(Directory.GetCurrentDirectory(),"wires-0.6.0-win.exe");
        service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";

        FirefoxDriver driver = new FirefoxDriver(service);

        driver.Navigate().GoToUrl("http://www.google.com");

但是我需要在初始化时向驱动程序添加配置文件才能设置代理。我以前是这样做的(对于较旧的 Firefox 版本)。

    private static IWebDriver InitialiseFirefoxDriver(Proxy proxy)
    {
        FirefoxProfile profile = new FirefoxProfile();

        if (proxy != null)
        {
            profile.SetProxyPreferences(proxy);
        }

        return new FirefoxDriver(profile);
    }

不幸的是,FirefoxDriver 构造函数只允许我传入 FirefoxDriverService 或 FirefoxProfile。有谁知道我可以设法在创建驱动程序之前(甚至之后)为驱动程序提供两组配置信息的方法?

谢谢。

【问题讨论】:

    标签: c# selenium selenium-webdriver ui-automation firefox-marionette


    【解决方案1】:

    这是使用 FirefoxProfile 和 FirefoxDriverService 的示例代码。我想隐藏 CommandPromptWindow 和静音。

    FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
    service.HideCommandPromptWindow = true;
    FirefoxProfile _Profile = new FirefoxProfile();
    _Profile.SetPreference("media.volume_scale", "0.0");
    FirefoxOptions option = new FirefoxOptions();
    option.Profile = _Profile;
    
    var driver = new FirefoxDriver(service,option,TimeSpan.FromSeconds(20));
    driver.Navigate().GoToUrl("https://www.youtube.com/watch?v=hxiitzCKRek");
    

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 2012-08-27
      • 1970-01-01
      • 2018-07-27
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      相关资源
      最近更新 更多