Can*_*unc 4 javascript cookies selenium node.js
我正在使用 Node.JS 的 selenium-webdriver npm 模块,但是我在将 cookie 写入控制台时遇到问题。我使用了NPM 页面中的示例代码(正在使用中)
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
console.log(driver.manage().getCookies());
driver.quit();
Run Code Online (Sandbox Code Playgroud)
现在,我希望 console.log 写入我在其他问题中看到的字典,但是我得到以下输出:
ManagedPromise {
flow_:
ControlFlow {
propagateUnhandledRejections_: true,
activeQueue_:
TaskQueue {
name_: 'TaskQueue::5',
flow_: [Circular],
tasks_: [Object],
interrupts_: null,
pending_: null,
state_: 'new',
unhandledRejections_: Set {} },
taskQueues_: Set { [Object] },
shutdownTask_: null,
hold_:
Timeout {
_called: false,
_idleTimeout: 2147483647,
_idlePrev: [Object],
_idleNext: [Object],
_idleStart: 231,
_onTimeout: [Function: wrapper],
_repeat: [Function] } },
stack_: { [Task: WebDriver.manage().getCookies()] name: 'Task' },
parent_: null,
callbacks_: null,
state_: 'pending',
handled_: false,
value_: undefined,
queue_: null }
Run Code Online (Sandbox Code Playgroud)
我的控制台中没有收到任何错误,但我也没有得到我期望的 cookie。我正在使用最新版本的node v5.9.1和最新版本的selenium-webdriver。由于某种原因,console.log 代码在Firefox 的 selenium 实例启动之前就被调用了。我该如何解决这个问题?
您可以使用.then()。请参阅我们何时应该将 .then 与 Protractor Promise 一起使用?了解更多信息。
driver.manage().getCookies().then(function (cookies) {
console.log(cookies);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3558 次 |
| 最近记录: |