Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
Getting webElementId as 'undefined' in Nightwatch
module.exports = {

'TESTTT'(browser){
  browser  
    .url ("https://xyz")
    .elements('xpath', '//div[@class="ant-card-head-title"]//span', function (elements) {
        console.log(elements.value)  // It prints all the three web elements
        elements.value.forEach(function (elementsObj) {
            console.log("WebElementID: " + elementsObj.ELEMENT)  // gives undefined
            browser.elementIdText(elementsObj.ELEMENT, function (result) {
                
                    console.log('\n' + result.value)
            
            })
        })

    })

  }
}

I am using Nightwatch for UI automation. There are three Web elements whose text I want to print. Before the ForEach loop when I print (elements.value) it gives me all the three elements. But when I print after ForEach, it gives 'undefined' value of a webElementId. Why is it giving undefined value?

Error Screenshot

enter image description here

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I am not sure what the .ELEMENT is supposed to be. if you are using vscode and u can't strg+click on ELEMENT then it doesn't exist.

If you want to get the value from the object try my modified code. It works for me ;)

module.exports = {

    'TESTTT'(browser){
      browser  
        .url ("https://xyz")
        .elements('xpath', '//div[@class="ant-card-head-title"]//span', function (elements) {
            console.log(elements.value)  // It prints all the three web elements
            elements.value.forEach(function (elementsObj) {
                // Changed Code below
                let elementID = elementsObj[Object.keys(elementsObj)[0]]
                console.log(`WebElementID: ${elementID}`) // Logs the first property value of the elementsObj
                browser.elementIdText(elementID, function (result) {
                // Changed Code above
                    
                        console.log('\n' + result.value)
                
                })
            })
    
        })
    
      }
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda