如何使用萤火虫启动硒火狐webdriver时自动关闭萤火虫标签?
问题描述:
我在启动firefox驱动程序时加入了firebug,它在最新的selenium web驱动程序3.0中工作得很好,但同时它也在每次启动浏览器时打开新的firebug选项卡。如何使用萤火虫启动硒火狐webdriver时自动关闭萤火虫标签?
正如代码所说,我已经包含firebug文件并在创建的配置文件中添加了此扩展名。启动浏览器后,有没有办法自动关闭萤火虫标签?如果没有自动方式,那么我需要使用调整来关闭名为“Firebug”的窗口吧?
代码:
File file = new File("./firebug-2.0.17-fx.xpi");
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("marionette", true);
webDriver = new FirefoxDriver(capabilities);
答
您可以设置 “showFirstRunPage” 标志为 “假” 在你的porfile。
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.showFirstRunPage", false);
以下是您可以设置的所有Firebug偏好设置的链接。 Firebug Preferences
另一种解决方法是将“currentVersion”设置为这样的大数字。
profile.setPreference("extensions.firebug.currentVersion", "999");
我宁愿先上;)
+0
非常棒!请接受这个问题。 –
答
我一直在寻找自动关闭Firebug的窗口,但我认为它不可能如此张贴的答案启动燃烧室浏览器与萤火功能后处理打开的窗口,不幸的是你需要处理额外的代码由于这个问题:)
下面的解决方案,它工作正常,只需使用它如下:
工作代码:
File file = new File("./firebug-2.0.17-fx.xpi");
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("marionette", true);
webDriver = new FirefoxDriver(capabilities);
// Close the firebug window
Thread.sleep(4000); // Firebug window takes time to open it
Set <String> windows = webDriver.getWindowHandles();
String mainwindow = webDriver.getWindowHandle();
for (String handle: windows) {
webDriver.switchTo().window(handle);
if (!handle.equals(mainwindow)) {
webDriver.close();
}
}
webDriver.switchTo().window(mainwindow);
你试过http://stackoverflow.com/questions/11449179/how-can-i-close-a-specific-window-using-selenium- webdriver与Java? – lauda
我已经在初步评论中已经添加,我正在寻找自动解决方案,但无论如何需要通过打开的窗口处理:)发布答案... –