我知道您可以加载现有的Firefox配置文件,或者在selenium-webdriver gem中使用Ruby Bindings创建一个,如下所述:
http://code.google.com/p/selenium/wiki/RubyBindings
然后使用add_extension向实例添加任意数量的Firefox扩展,但那又是什么?我正在使用的扩展窗口在测试期间不会出现.我该如何使用扩展程序?
有没有办法在驱动程序打开Firefox时默认打开扩展程序?
这是我正在使用的代码:
#!/usr/bin/env ruby
require "rubygems"
require "selenium-webdriver"
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.add_extension("/Users/******/Library/Application Support/Firef\
ox/Profiles/wvon3h99.default/extensions/{9c51bd27-6ed8-4000-a2bf-36cb95c0c947}.\
xpi")
driver = Selenium::WebDriver.for(:firefox, :profile => default_profile)
driver.navigate.to "http://google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit
Run Code Online (Sandbox Code Playgroud) 我正在修改篡改数据,这将允许我将它观察到的HTTP请求/响应发送到服务器.到目前为止,该功能已正确实施.下一步是自动执行此过程,我希望使用"复选框"类型的工具栏菜单按钮来打开和关闭此功能.
到目前为止,我在.XUL中有一些代码:
<toolbarbutton id="tamper.autosend" label="&tamper.toolbar.autosend;" type="checkbox" oncommand="oTamper.toggleTimer();"/>
Run Code Online (Sandbox Code Playgroud)
而这个功能在我的扩展的主要驱动程序中:
toggleTimer : function() {
var checked = document.getElementById('tamper.autosend').checked;
var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
consoleService.logStringMessage(checked);
if (checked) {
var interval = window.setInterval(function(thisObj) { thisObj.sendResults(true); }, 1000, this);
}
else {
window.clearInterval(interval);
}
}
Run Code Online (Sandbox Code Playgroud)
使用consoleService我看到'checked'的值确实是正确的.我认为问题在于我如何调用clearInterval,但我不确定如何解决它.
任何帮助是极大的赞赏!