Selenium+Firefox:如何同时使用 Firefox 二进制规范和 Firebug 扩展添加?
Selenium+Firefox: How can I go with both Firefox binary specification and Firebug extension addition?
目前我正在使用以下代码。
var co = require('co');
var WebDriver = require('selenium-webdriver');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
co(function *() { // async
var server = new SeleniumServer('/path/to/selenium', {
port: 4444,
jvmArgs: ['-Dwebdriver.firefox.bin=path/to/firefox'] // Firefox binary specification
});
yield server.start(); // await
var driver = new WebDriver
.Builder()
.usingServer(server.address())
.withCapabilities(WebDriver.Capabilities.firefox())
.build();
});
现在我需要添加 Firebug 扩展以将网络流量提取为 *.har
文件。我用谷歌搜索找到 this:
var firefox = require('selenium-webdriver/firefox');
var profile = new firefox.Profile();
profile.addExtension('/path/to/firebug.xpi');
profile.setPreference('extensions.firebug.showChromeErrors', true);
var options = new firefox.Options().setProfile(profile);
var driver = new firefox.Driver(options);
看到这个,好像有以下几种方法:
firefox.Options().setProfile()
firefox.Options().setBinary()
然而,firefox.Options()
总是return什么都没有...
怎么回事?
根据 source code,Options()
函数调用应该 return 没有:
var Options = function() {
/** @private {Profile} */
this.profile_ = null;
/** @private {Binary} */
this.binary_ = null;
/** @private {webdriver.logging.Preferences} */
this.logPrefs_ = null;
/** @private {webdriver.ProxyConfig} */
this.proxy_ = null;
};
您需要使用new
来初始化Options
对象:
var options = new firefox.Options();
console.log(options);
这会有很多可用的方法,包括setProfile()
、setBinary()
等
目前我正在使用以下代码。
var co = require('co');
var WebDriver = require('selenium-webdriver');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
co(function *() { // async
var server = new SeleniumServer('/path/to/selenium', {
port: 4444,
jvmArgs: ['-Dwebdriver.firefox.bin=path/to/firefox'] // Firefox binary specification
});
yield server.start(); // await
var driver = new WebDriver
.Builder()
.usingServer(server.address())
.withCapabilities(WebDriver.Capabilities.firefox())
.build();
});
现在我需要添加 Firebug 扩展以将网络流量提取为 *.har
文件。我用谷歌搜索找到 this:
var firefox = require('selenium-webdriver/firefox');
var profile = new firefox.Profile();
profile.addExtension('/path/to/firebug.xpi');
profile.setPreference('extensions.firebug.showChromeErrors', true);
var options = new firefox.Options().setProfile(profile);
var driver = new firefox.Driver(options);
看到这个,好像有以下几种方法:
firefox.Options().setProfile()
firefox.Options().setBinary()
然而,firefox.Options()
总是return什么都没有...
怎么回事?
根据 source code,Options()
函数调用应该 return 没有:
var Options = function() {
/** @private {Profile} */
this.profile_ = null;
/** @private {Binary} */
this.binary_ = null;
/** @private {webdriver.logging.Preferences} */
this.logPrefs_ = null;
/** @private {webdriver.ProxyConfig} */
this.proxy_ = null;
};
您需要使用new
来初始化Options
对象:
var options = new firefox.Options();
console.log(options);
这会有很多可用的方法,包括setProfile()
、setBinary()
等