Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda