I have an innerText that changed after 2-3 sec from Loading
to Play
. I would like to wait for the innerText to change to Play
. I'm using the following code :
let attempt = 0;
let maxRetries = 4;
let payerButtonStatus = await this.player_page.innerText('#playingStatus');
while (attempt < maxRetries) {
if (payerButtonStatus !== 'Loading') {
console.log(`payerButtonStatus = ${payerButtonStatus}`);
return true;
}
console.log(`Playback button status is - ${payerButtonStatus}, wait for 1sec and continue... ${attempt}/${maxRetries}`);
await this.player_page.waitForTimeout(1000);
payerButtonStatus = await this.player_page.innerText('#playingStatus');
console.log(`payerButtonStatus= ${payerButtonStatus}`);
attempt++;
}
return false;
Is there a better code to write this ?
You can use a text selector on a waitForSelector. It will wait for 30 seconds by default:
await this.player_page.waitForSelector('text=Play');