admin管理员组文章数量:1026989
I'm using the selenium-webdriver npm module for Node.JS, however I am having trouble writing the cookies to the console. I used the example code from the NPM page (Under usage)
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('');
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();
Now, I would expect console.log to write the dictionary I've seen referenced in other questions, however I get the following output:
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 }
I get no errors in my console, but I'm not getting the cookies I expected either. I'm using the latest version of node, v5.9.1, and the latest version of selenium-webdriver. For some reason the console.log code is called before selenium's instance of Firefox even starts. How would I go about fixing this?
I'm using the selenium-webdriver npm module for Node.JS, however I am having trouble writing the cookies to the console. I used the example code from the NPM page (Under usage)
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google./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();
Now, I would expect console.log to write the dictionary I've seen referenced in other questions, however I get the following output:
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 }
I get no errors in my console, but I'm not getting the cookies I expected either. I'm using the latest version of node, v5.9.1, and the latest version of selenium-webdriver. For some reason the console.log code is called before selenium's instance of Firefox even starts. How would I go about fixing this?
Share Improve this question asked Mar 29, 2016 at 18:38 CanduncCandunc 1082 silver badges9 bronze badges1 Answer
Reset to default 6You can use .then(). Refer to When should we use .then with Protractor Promise? for more information.
driver.manage().getCookies().then(function (cookies) {
console.log(cookies);
});
I'm using the selenium-webdriver npm module for Node.JS, however I am having trouble writing the cookies to the console. I used the example code from the NPM page (Under usage)
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('');
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();
Now, I would expect console.log to write the dictionary I've seen referenced in other questions, however I get the following output:
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 }
I get no errors in my console, but I'm not getting the cookies I expected either. I'm using the latest version of node, v5.9.1, and the latest version of selenium-webdriver. For some reason the console.log code is called before selenium's instance of Firefox even starts. How would I go about fixing this?
I'm using the selenium-webdriver npm module for Node.JS, however I am having trouble writing the cookies to the console. I used the example code from the NPM page (Under usage)
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google./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();
Now, I would expect console.log to write the dictionary I've seen referenced in other questions, however I get the following output:
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 }
I get no errors in my console, but I'm not getting the cookies I expected either. I'm using the latest version of node, v5.9.1, and the latest version of selenium-webdriver. For some reason the console.log code is called before selenium's instance of Firefox even starts. How would I go about fixing this?
Share Improve this question asked Mar 29, 2016 at 18:38 CanduncCandunc 1082 silver badges9 bronze badges1 Answer
Reset to default 6You can use .then(). Refer to When should we use .then with Protractor Promise? for more information.
driver.manage().getCookies().then(function (cookies) {
console.log(cookies);
});
本文标签: javascriptSelenium NodeJS print cookies to consoleStack Overflow
版权声明:本文标题:javascript - Selenium NodeJS print cookies to console - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745650437a2161286.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论