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?
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)
})
})
})
}
}