剧作家 waitFor 将 innerText 更改为精确值

Playwright waitFor changed innerText to be exact value

我有一个 innerText 在 2-3 秒后从 Loading 更改为 Play 。我想等待 innerText 更改为 Play。我正在使用以下代码:

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;

有没有更好的代码来写这个?

您可以使用 text selector on a waitForSelector。默认等待30秒:

await this.player_page.waitForSelector('text=Play');