.goto().click().then()
, yes
.goto().click()
queues events
.then()
.
credits.md
or something
.then()
?
Promise.then()
"
I see. So...
.then(function(result) {
console.log(result);
})
Will do all the methods above it, then print the output of .end()
to the console?
.end()
is an edge case
.end()
will actually bubble the previous function's output, i think
nightmare.goto(someUrl)
.click(someSelector)
.title()
.end()
.then(function(title){
console.log('title: ' + title);
})
nightmare.goto(someUrl)
.click(someSelector)
.title()
.wait(someMs)
.then(function(title){
console.log('title: ' + title);
})
title
will be undefined
In #491, you said:
I guess getting back to a point @Mr0grog made: I am biased for using yield.
What would yield
be the alternative for?
yield
in conjunction with vo
or co
can be pretty useful
var vo = require('vo');
var Nightmare = require('nightmare');
var run = function*() {
var nightmare = Nightmare();
var title = yield nightmare
.goto(someUrl)
.title();
var somethingVisible = yield nightmare.visible('.my-super-awesome-class');
yield nightmare.end();
return {title: title, visible: somethingVisible};
}l;
vo(run)(function(err, result){
//result is the object returned from "run"
});
yield
makes it pretty straightforward to pluck data as you need it, but there's certainly nothing stopping you from using promises to accomplish the same thing
yield
will save information that you can work with later?
function*()
bit) are ... more complicated than that
yield
like a placeholder for asynchronous functions to put their value when they're finished
yield nightmare.title()
line is saying "hey, eventually there will be the title here, wait for it"
.wait(5000)
in my program, but my program takes less than a second to run. Is this supposed to happen?
actions.post()
doesn't have a .then()
botland.botland-thread
... dashes aren't legal in bare identifiers as it'll try to do math
botland['botland-thread']
.wait()
?
@rosshinkley Can someone help me with this code. It returns empty objects.
var Nightmare = require('nightmare');
var startingLink = "http://stackoverflow.com"
var nightmare = Nightmare({show:true});
nightmare
.goto(startingLink)
.evaluate(function() {
return document.getElementsByClassName('question-hyperlink')
})
.end()
.then(function(content) {
console.log(content);
})
I don't know what's wrong with it.
visible:true
?
HTMLCollection
and DOMElement
don't serialize nicely
document.getElementsByClassname
returns an HTMLCollection
, which isn't an arrray
arguments
in function(){ ...
map
or slice
var nightmare = Nightmare({visible: true});