【问题标题】:Geckodriver 0.16.0 start firefox with flashplayerGeckodriver 0.16.0 使用 Flash 播放器启动 Firefox
【发布时间】:2017-09-23 21:52:25
【问题描述】:

由于 geckodriver v0.16.0 flashplayer 默认被禁用。 是否有可能在启用 flashplayer 的情况下启动 firefox?

我正在使用 C#。我现在的代码:

var profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("selenium"); //created firefox user named selenium
profile.SetPreference("plugin.state.flash", 1);

下面的代码对我不起作用:

profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", true);

当我使用这个时:

profile.SetPreference("plugin.state.flash", 1);

firefox 询问我是否要启用 flashplayer,然后刷新页面(之前填写了所有输入 - 所以我得到了空字段)。 如果我选择“允许并记住”,下次我启动此代码时不会保存任何内容。我也遇到了同样的情况。

【问题讨论】:

  • 我昨天用最新的 geckodriver 遇到了同样的问题。我能够暂时切换到 chrome,但也想知道如何解决这个问题。
  • 您能否分享您在使用 flashplayer 时遇到问题的网站,以防它是公共网址?
  • 我在每一页都有这个问题。例如:adobe.com/swf/software/flash/about/flashAbout_info_small.swf
  • 我的问题是您要测试/自动化哪个网站,您要为其启用 flashplayer?
  • 很遗憾,我无法链接该网站。但是在所有其他网站上,问题都是一样的。我认为,即使我可以,它也不会改变任何事情。

标签: c# selenium flash geckodriver firefox-marionette


【解决方案1】:

我在那里找到了解决方案: How to enable Adobe Flash in FireFox Selenium webdriver with FirefoxProfile

如果我将 profile.setPreference("plugin.state.flash", 1); 替换为 profile.setPreference("plugin.state.flash", 2);,它会停止询问我是否要启用 Flash 播放器。

【讨论】:

    【解决方案2】:

    以下是适合您的解决方案:

    对于 Selenium 4.3.0、gecko 驱动程序 v0.16.0 和 Mozilla Firefox 53.0,此代码适用于 myfreecams.com。

    值得一提的是,默认的 Firefox 配置文件对自动化不是很友好。当您想在 Firefox 浏览器上可靠地运行自动化时,建议制作一个单独的配置文件。自动化配置文件应该很容易加载并具有特殊的代理和其他设置来运行良好的测试。您应该与您在所有开发和测试执行机器上使用的配置文件保持一致。如果您在各处使用不同的配置文件,那么您接受的 SSL 证书或您安装的插件会有所不同,这会使测试在机器上的行为有所不同。

    因此,创建一个新的 Firefox 配置文件并在测试脚本中使用相同的配置文件涉及三个步骤。首先您需要启动配置文件管理器,其次是创建一个新配置文件,第三是在测试脚本中使用相同的配置文件。假设我们创建了一个名为“debanjan”的新 FirefoxProfile。

    使用以下代码使用您的新 FirefoxProfile “debanjan”打开 http://www.myfreecams.com/

        String driverPath = "C:\\Utility\\BrowserDrivers\\";
        //Mozila Firefox
        System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile testprofile = profile.getProfile("debanjan");
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        dc.setCapability(FirefoxDriver.PROFILE, testprofile);
        FirefoxDriver driver =  new FirefoxDriver(dc);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
        driver.navigate().to("http://www.myfreecams.com/");
    

    PS:此代码是 Java 代码,因此您可能需要将其转换为 C# 格式。

    如果这对你有帮助,请告诉我。

    【讨论】:

    • 当您执行此代码时,Flashplayer 是否在您的菜单->插件->插件中打开?对我来说,每次运行此代码时它仍然关闭
    • 不管为默认 Firefox 配置文件打开或关闭 flashplayer,我都创建了一个名为“debanjan”的新 Firefox 配置文件并访问了该网站。它适用于我的答案中提到的配置以及最近发布的 gecko v0.16.1
    • @Edvac 你还有什么问题吗?
    • 如果我使用此代码更改为 C#,我收到错误:Invalid moz:firefoxOptions field acceptInsecureCerts。如果我改变这个: DesiredCapabilities dc = DesiredCapabilities.Firefox(); dc.SetCapability(FirefoxDriver.ProfileCapabilityName, profile); FirefoxDriver 驱动程序 = 新的 FirefoxDriver(dc);对此(如编译器所说): FirefoxOptions fo = new FirefoxOptions(); fo.AddAdditionalCapability(FirefoxDriver.ProfileCapabilityName,配置文件); FirefoxDriver 驱动程序 = 新的 FirefoxDriver(fo);它抛出: firefox_profile 功能已经有一个选项。请改用它。
    猜你喜欢
    • 2017-06-23
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    相关资源
    最近更新 更多