当运行Selenium 2时,激活Firefox中的Firebug最佳方法是什么?
编辑:好的,我意识到“最佳”是可以解释的,但是基于配置文件的解决方案在selenium 1.0中确实很痛苦。因此,任何替代方案都被认为比之前更好,除非证明更差 ;)
当运行Selenium 2时,激活Firefox中的Firebug最佳方法是什么?
编辑:好的,我意识到“最佳”是可以解释的,但是基于配置文件的解决方案在selenium 1.0中确实很痛苦。因此,任何替代方案都被认为比之前更好,除非证明更差 ;)
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);
这在WebDriver FAQ中有详细描述。
您是否是指在webdriver启动的浏览器实例中安装Firebug?如果是这样,您可以在实例化驱动程序时传递一个扩展,但最简单的方法是创建一个已安装Firebug的Firefox配置文件,然后在实例化驱动程序之前使用以下代码:
System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");
只需要通过名称引用您的个人资料。例如,Ruby代码示例:
@driver = Selenium::WebDriver.for :firefox, :profile => "default"
然后,正常加载Firefox,并添加所需的扩展程序。它们现在将显示在您的Selenium测试运行中。
显然,在Selenium WebDriver中,firefox-profile选项的使用方式已经发生了变化。
旧的命令行(Selenium RC):
java -jar selenium-2.28.0.jar -firefoxProfileTemplate ~/.mozilla/firefox/3knu5vz0.selenium
更新WebDriver:(请注意,它需要配置文件的名称而不是目录)
java -jar selenium-2.28.0.jar -Dwebdriver.firefox.profile=selenium
我注意到Firebug会添加到浏览器中,并且默认情况下是禁用的。当我在运行时使用WebDriver将Firebug添加到Firefox中时,它仍然没有启用。因此,为了使其启用,我们可能需要将以下行添加到配置文件中。
profile.setEnableNativeEvents(true);
如果以上选项都不起作用,请尝试以下方法。
firefox -p
5)现在通过Selenium加载此新配置文件,使用以下Java语句。
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
6)完成。享受吧。
修改Firefox的位置,例如:C:\Users\user-name\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default,在Selenium/Webdriver中启动Firefox浏览器,进行所需的所有设置,然后关闭并重新启动Firefox浏览器。就这样,它可以解决您的问题!!
java -jar selenium.jar -Dwebdriver.firefox.profile=default
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1")
(或您使用的任何版本)以便禁止 FireBug 的启动页面显示。 - iCollect.it Ltd