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

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

问题描述

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

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

然后使用 add_extension 将任意数量的 Firefox 扩展添加到实例中,然后呢?我正在使用的扩展程序的窗口在测试期间没有出现.如何使用扩展程序?

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?

有没有办法在驱动打开 Firefox 时默认打开扩展?

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

推荐答案

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

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

我使用的扩展程序通常具有某种自动导出功能,可以自动将数据发送到服务器或将其保存在磁盘上.恐怕无法使用 WebDriver 控制扩展,因此并非所有扩展都可用于自动化测试.

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天全站免登陆