Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I wait until elements matching multiple selectors appear?

Tags:

playwright

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?

like image 768
PaleNeutron Avatar asked Apr 17 '26 02:04

PaleNeutron


1 Answers

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").

like image 114
Yevhen Laichenkov Avatar answered Apr 29 '26 20:04

Yevhen Laichenkov