Nightmare JS cannot get Button Element

53 views Asked by At

I am trying to do some simple nightmare.js. The problem is that I cannot get one specific button.

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

nightmare
  .goto('https://account.parkmobile.com/login')
  .wait(3000)
  .type('#username', '')
  .wait(2000)
  .type('#login_password', '')
  .wait(2000)
  .evaluate(function() {
    let loginBtns = document.getElementsByClassName("btn btn-primary btn-block")
    for (let loginBtn of loginBtns) loginBtn.click()
        })

  .wait(4000)
  .evaluate(function() {
  let newSessions = document.getElementsByClassName("btn btn-primary add-button close-panel-margin ng-star-inserted")
  for (let newSession of newSessions) newSession.click()
      })
  .wait(4000)
  .type("#zone > div > input", "21789")
  .wait(3000)
  .click("#zone > div > div > div > div")  
  .wait(4000)
  .evaluate(function() {
    let newStarts= document.getElementsByClassName("btn btn-primary btn-block ng-tns-c36-26")
    for (let newStart of newStarts) newStart.click()
        })
  .wait(3000)
  .end()
  .then(console.log)
  .catch(error => {
    console.error('Search failed:', error)
  })

I am talking about this line:

  .evaluate(function() {
    let newStarts= document.getElementsByClassName("btn btn-primary btn-block ng-tns-c36-26")
    for (let newStart of newStarts) newStart.click()
        })

enter image description here

Could it be that it has to do something with this text: _ngcontent-uei-c203 after the <button

Maybe someone can help clicking on "Start this parking" button. :)

Thanks for the help!

0

There are 0 answers