For example, I'm testing a search page, which will show the result numbers in .text > span:nth-child(1).
However, if not any result, it will only show text="nothing" or .text > span:nth-child(1) does not exist.
How can I wait for both conditions?
You need to use a comma-separated list of CSS selectors which will match all elements that can be selected by one of the selectors in that list:
// ↓ comma
await page.locator('.text > span:nth-child(1), span:has-text("nothing")').innerText();
It will wait for either .text > span:nth-child(1) or span:has-text("nothing").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With