Nightmare.js can't find css tag

51 Views Asked by At

I am currently developing a program to automate a task on a certain website (the simplified code is below).
I login nicely and then wait for the page to load, but the wait function never ends. I tried using wait(200), but then the evaluate function returns an empty array. I am 100% sure there are p.reference elements in the website.
Does anyone know what is happening?

const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })

nightmare

  .goto('https://somewebsite.com')
  
  .insert('input#username', '[email protected]')
  .insert('input#password', 'abc') 
  .click('button#Login')
  .wait('p.reference')
  .evaluate(selector=>{
    return document.querySelectorAll(selector)
  },'p.reference'
  )
  .end()
  .then(console.log)
  .catch(error => {
    console.error('Search failed:', error)
})
1

There are 1 best solutions below

1
Riccardo Bertolini On

I think the problem is with the password lookup. Since you're looking for a field with the class password so you need to change into

  .insert('input#password', 'abc') 

OR

  .insert('input.password', 'abc') 

But I would bet is the first one, according to the other field.