vendredi 31 mai 2019

With If statement Page load error works, but page load success does not

When running If statement, upon page element not being present, page load fails and produces a correct error message, but when the element is present, both conditions run, success code operation as well as failure operation.

Tried await page.waitForSelector and await page.$(selector) both did not work and

await page.waitForSelector('#example').then(() => {
  console.log('SUCCESS');
}).catch(e => {
  console.log('FAIL');
});

if (await page.$('.SELECTOR') !== null)
console.log(success(await page.title() + ' SUCCESS LOAD 1 - URL Page Load'));  // console log   
// on success continue below
else
console.log(error(await page.title() + ' FAIL LOAD 1 - URL Page Load'));  // console log    
await page.screenshot({path: './screenshots/Fail_Load_1_PageDidNotLoad.jpeg'}); // screenshot
await page.evaluate(() => alert('FAIL LOAD 1 - URL Page Did Not Load'));  // pop up alert
await browser.close();  // release memory  
return process.exit(1); // exit process

How to correctly incorporate a THEN.

Aucun commentaire:

Enregistrer un commentaire