So right now I have this code which grabs the results and it works great:
module.exports = async function grabResult(page) {
const message = await page.$eval(
'div > div:nth-child(2)',
(el) => el.innerText
);
const username = await page.$eval(
'child(15) .username',
(el) => el.innerText
);
return { message, username };
};
console.log(result);
The above code output:
{ message: 'message text goes here', username: 'John' }
What I'm trying to do is before returning the result, to check if the 'message' contains certain words.
If the 'message' contains "http", "https" for example, then it would return empty (which is what I need):
{ message: '', username: 'John' }
If it DOESN'T contain "http", "https", then it would return the 'message' result as my original code.
{ message: 'message text goes here', username: 'John' }
I know there's a command that checks if the text contains x. I found this piece of code on the other thread:
if ((await page.waitForXPath('//*[contains(text(), "Subscription Confirmed")]',30000)) !== null) {
chk = await page.evaluate(el => el.innerText, await page.$x('//*[contains(text(), "Subscription Confirmed")]'))
chk = 'Success'
} else {
chk = 'Failed'
}
But I'm struggling to combine those two into one code.
Any help would be greatly appreciated.
I'm not a coder, hope I'm clear..