如何在Selenium WebDriver(Selenium 2)中运行Firebug?

kro*_*old 26 java firebug selenium-webdriver

在运行Selenium 2时,在Firefox中激活Firebug的最佳方法是什么?

编辑:好的,我意识到"最好的"是开放的解释,但基于配置文件的解决方案真的曾经是selenium 1.0的痛苦.所以任何替代方案都被认为更好,直到证明更糟;

Ser*_*rov 47

您可以在代码中创建配置文件并动态添加所需的附加组件.假设您将Firebug XPI作为firebug.xpi保存到C:\ FF_Profile文件夹中(转到Firebug下载页面,右键单击"添加到Firefox"并保存为C:\ FF_Profile\firebug.xpi).

在代码中:

   final String firebugPath = "C:\\FF_Profile\\firebug.xpi";
   FirefoxProfile profile = new FirefoxProfile();       
   profile.addExtension(new File(firebugPath));
   // Add more if needed
   WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

这在WebDriver FAQ中有所描述

  • 您还想添加`firefoxProfile.setPreference("extensions.firebug.currentVersion","1.8.1")`(或您使用的任何版本),以便抑制FireBug启动屏幕. (5认同)

小智 10

你的意思是在webdriver启动的浏览器实例中安装了firebug吗?如果是这样,您可以在实例化驱动程序时传递扩展,但最简单的方法是创建安装了firebug的firefox配置文件,然后在实例化驱动程序之前使用以下代码:

System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");