Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playwright waitFor changed innerText to be exact value

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 ?

like image 276
Ida Amit Avatar asked Mar 18 '26 00:03

Ida Amit


1 Answers

You can use a text selector on a waitForSelector. It will wait for 30 seconds by default:

await this.player_page.waitForSelector('text=Play');
like image 155
hardkoded Avatar answered Mar 20 '26 12:03

hardkoded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!