如何访问我在Selenium Webdriver中添加的Firefox扩展? [英] How to access Firefox Extension I added in Selenium Webdriver?

查看:465
本文介绍了如何访问我在Selenium Webdriver中添加的Firefox扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以加载现有的Firefox配置文件,或者在selenium-webdriver gem中使用Ruby绑定创建一个,如下所述:

http://code.google.com/p/selenium/wiki/RubyBindings



然后使用 add_extension 向该实例添加任意数量的Firefox扩展,但那又如何?我正在使用的扩展程序的窗口在测试期间没有出现。如何使用扩展?



有没有办法让驱动程序打开Firefox默认情况下打开扩展?



下面是我正在使用的代码:

$ $ $ $ $ $ $ $ $#$ / usr / bin / env ruby​​
需要rubygems
需要selenium-webdriver

default_profile = Selenium :: WebDriver :: Firefox :: Profile.from_namedefault
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.tohttp://google.com

element = driver.find_element(:name,'q')
element.send_keysHello WebDriver!
element.submit

puts driver.title

driver.quit


解决方案

这取决于扩展名。通常,在创建FF配置文件时,可以通过设置适当的属性(在about:config中可找到的属性)来控制扩展的行为。例如,在FF启动后默认打开Firebug窗口,我会在代码中包含以下代码:

  default_profile [extensions .firebug.allPagesActivation] = true 

我使用的扩展通常具有某种自动导出功能自动发送数据到服务器或保存在磁盘上。恐怕没有办法通过WebDriver来控制扩展,所以并不是所有扩展都可以在自动化测试中使用。


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

解决方案

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:

default_profile["extensions.firebug.allPagesActivation"] = true

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.

这篇关于如何访问我在Selenium Webdriver中添加的Firefox扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆