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

我试图运行一个 selenium 脚本,该脚本单击我工具栏中的一个 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

相关文章