Geckodriver 0.16.0 使用 flash 播放器启动 firefox
Geckodriver 0.16.0 start firefox with flashplayer
由于 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,然后刷新页面(之前已填写所有输入 - 所以我有空字段)。
如果我 select "allow and remember",下次我启动此代码时,不会保存任何内容。我遇到了同样的情况。
这是适合您的解决方案:
对于 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# 格式。
如果对你有帮助,请告诉我。
我在那里找到了解决方案:
如果我将 profile.setPreference("plugin.state.flash", 1);
替换为 profile.setPreference("plugin.state.flash", 2);
,它就会停止询问我是否要启用 Flash 播放器。
由于 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,然后刷新页面(之前已填写所有输入 - 所以我有空字段)。 如果我 select "allow and remember",下次我启动此代码时,不会保存任何内容。我遇到了同样的情况。
这是适合您的解决方案:
对于 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# 格式。
如果对你有帮助,请告诉我。
我在那里找到了解决方案:
如果我将 profile.setPreference("plugin.state.flash", 1);
替换为 profile.setPreference("plugin.state.flash", 2);
,它就会停止询问我是否要启用 Flash 播放器。