I am conducting a test to verify if the textfield input is empty.
While working with Nightwatch and using the browser.execute() command, I encountered an issue where adding simple JavaScript code to check if a textfield is empty resulted in Nightwatch skipping the block of code. Interestingly, when I run the same JS code in the dev tools, it works perfectly fine but fails within Nightwatch. It's possible that I am misunderstanding the usage of browser.execute, so any insight into what might be going wrong would be greatly appreciated.
Thank you in advance for your help.
Nightwatch code
this.api.execute(
function() {
let element = document.getElementById('autocomplete-input').value;
console.log(element);
if(element.length == 0 || element === ""){
console.log('Element is empty')
}
})
},
JS code
function testing1() {
let element = document.getElementById('autocomplete-input').value;
console.log(element);
if(element.length == 0 && element === ""){
console.log('Element is empty')
}
}