Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!