如何在用java编写的selenium webdriver程序中使用Firefox插件?

如何在用java编写的selenium webdriver程序中使用Firefox插件?

问题描述:

我试图运行一个硒脚本,点击我的工具栏中的一个Firefox插件。是否有可能做到这一点?

I was trying to run a selenium script that clicks on one of my firefox plugins in my toolbar. Is it possible to do this?

事实上,你不能在元件上按一下,因为它不是一个网页元素。不过,您可以为Firefox创建一个配置文件,并在该配置文件中包含由webdriver应用程序启动的插件。这将允许您访问Firebug或其他插件。我不确定插件之间的相互作用,因为我不使用这个,但是设置配置文件和扩展插件api的配置文件的方式如下所示:

Actually you can't click on the element since it's not a web page element. However you can create a profile for firefox and include addons in that profile that is launched by the webdriver applications. This will allow you to have access to Firebug or other addons. I'm not sure of the interaction between the addons myself since I don't use this but the way you set a profile and extend the profile with the addon api is like so:

File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);

引用 - http://code.google.com/p/selenium/wiki/FirefoxDriver