如何访问我在 Selenium Webdriver 中添加的 Firefox 扩展?
我知道您可以加载现有的 Firefox 配置文件,或者使用 selenium-webdriver gem 中的 Ruby 绑定创建一个配置文件,如下所述:
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
I know that you can load up either an existing Firefox profile, or create one using Ruby Bindings in the selenium-webdriver gem, as described here:
http://code.google.com/p/selenium/wiki/RubyBindings
And then use add_extension
to add any number of Firefox extensions to the instance, but then what? The window for the extension I'm using does not appear during the test. How do I use the extension?
Is there a way to have the extension be open by default when the driver opens Firefox?
Here is the code I'm using:
#!/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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于扩展。通常,在创建 FF 配置文件时,可以通过设置适当的属性(可以在 about:config 中找到的属性)在某种程度上控制扩展的行为。例如,要在 FF 启动后默认打开 Firebug 窗口,我将在代码中包含以下行:
我使用的扩展通常具有某种自动导出功能,可以自动将数据发送到服务器或将其保存在磁盘上。恐怕无法使用 WebDriver 控制扩展,因此并非所有扩展都可用于自动化测试。
It depends on extension. Usually the extension's behaviour can be to some extent controlled by setting appropriate properties (the ones you can find in about:config) when creating an FF profile. For instance to have Firebug window open by default after FF starts I would include the following line in my code:
The extensions I use usually have some kind of auto-export feature that automatically sends data to server or saves it on disk. I am afraid there is no way of controlling an extension with WebDriver so not all extensions will be usable in automated tests.