setversionNumber = async (index, page) => {
const input = await page.evaluateHandle((i) => {
const versionView = document.getElementsByClassName("mx-dataview mx-name-dataView9")[0];
const inputfield = versionView.getElementsByTagName('input')[i];
if (inputfield.value === null || inputfield.value === '' ) {
console.info('returning input');
return inputfield;
}
console.info('returning null');
return null;
}, index);
if (await input !== null) {
console.info('input is filled');
const content = await page.evaluate((i) => i.value, input);
console.log(content);
await input.type('1');
} else {
console.info('input is empty');
}
I got this code which needs to get an input field and type '1' if the input's value is empty.
When i run it in the browser the console logs 'retruning null' which is expected, because the inputs value is empty.
But when checking if the returned input is actually null, it logs that the 'input is filled' . And after that an error is thrown, saying 'cannot read property "value" of null'. Which means input is actually null. So i think i'm just not using the right check to see if this input object is actaully null.
Is there an other way to check if a returned object from page.evaluateHandle is empty/null?
question from:
https://stackoverflow.com/questions/65887292/how-to-check-if-jshandle-returned-from-page-evaluatehandle-is-empty-null 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…