These are chat archives for rosshinkley/nightmare

11th
Jul 2017
Mingsterism
@mingsterism
Jul 11 2017 02:15
hey guys
once i evaluate an element and get some text, how can i use .type to type into a field?
this is what i got so far
var Nightmare = require('nightmare')
var nightmare = Nightmare({ show: true });

nightmare
    .goto('example.com')
    .evaluate( () => {
        return document.getElementById('row1').innerText
    })
    .then((words) => {
        yield nightmare 
            .type('input[id="input-field"]', 'sample text input text')
            .end()
            console.log(words)
    })
    .catch((err) => {
        console.error("Extracting words failed", error);
words is a string of words
Davide De Gennaro
@dege88
Jul 11 2017 08:00
why are you using yield?
that code seems fine to me, it isn't working at all?
Mingsterism
@mingsterism
Jul 11 2017 08:01
im not too sure. i just seen examples using yield
but my main question is how to use .type inside a then() function?
is it like that?
Davide De Gennaro
@dege88
Jul 11 2017 08:46
yes
but remember to alway add a then after an end
and i'll suggest a delay after the .type to view the typed text
Mingsterism
@mingsterism
Jul 11 2017 21:10
@dege88 can get help on this code? I get an error when run.
var Nightmare = require('nightmare')
var nightmare = Nightmare({ show: true });

nightmare
    .goto('https://10fastfingers.com/typing-test/english')
    .evaluate( () => {
        return document.getElementById('row1').innerText
    })
    .then((words) => {
        return nightmare
            .type('input[id="input-field"]', 'sample text input text')
            .end()
            .then((x) => {
                console.log('typing done')
            })
            .catch((err) => {
                console.log("unable to type into box", err)
            })
            console.log('-------------------');
    })
    .catch((err) => {
        console.error("Extracting words failed", error);
    })