Geckodriver 0.16.0使用FlashPlayer启动Firefox



因为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,而不是刷新页面(以前所有输入都填写了 - 所以我有空字段(。如果我选择"允许并记住",下次我启动此代码时,请保存此代码。我得到了相同的情况。

我在那里找到了解决方案:如何使用FirefoxProfile

在Firefox Selenium Webdriver中启用Adobe Flash

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

这是您的解决方案:

使用Selenium 4.3.0,壁虎驱动程序V0.16.0&Mozilla Firefox 53.0此代码与MyFreeCams.com配合得很好。

值得一提的是,默认的firefox配置文件不是很友好。当您想在Firefox浏览器上可靠地运行自动化时,建议您进行单独的配置文件。自动化配置文件应轻巧,并具有特殊的代理和其他设置以进行良好的测试。您应该与所有开发和测试执行机上使用的配置文件一致。如果您到处使用了不同的配置文件,则您接受的SSL证书或安装的插件将有所不同,这会使测试在计算机上的行为不同。

因此,创建一个新的Firefox配置文件,并在测试脚本中使用相同的内容涉及三个步骤过程。首先,您需要启动配置文件管理器,其次是创建一个新的配置文件,第三个是在测试脚本中使用相同的配置文件。假设我们用名称" Debanjan"创建了一个新的Firefoxprofile。

使用以下代码打开http://www.myfreecams.com/使用您的新FirefoxProfile" Debanjan":

    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#格式。

让我知道,如果这对您有帮助。

最新更新