4

I am trying to await a div that has one of two possible ids, div#abc or div#efg.

I can await div#abc like this:

    await this.page.waitForSelector('div#abc');

But how can I tell Playwright that I also want the step to pass if div#efg is present?

Patrick Kenny
  • 4,515
  • 7
  • 47
  • 76

2 Answers2

4

Like with Puppeteer, Playwright selectors can be standard CSS, so just add a comma between the selectors:

await this.page.waitForSelector('div#abc, div#efg');
Patrick Kenny
  • 4,515
  • 7
  • 47
  • 76
2

More general solution that works for any number of async operations:

const firstResolvedPromiseResult = await Promise.race([
  this.page.waitForSelector('div#abc'),
  this.page.waitForSelector('div#efg'),
]);

But the accepted solution is simpler for this use case.

atmin
  • 1,231
  • 1
  • 8
  • 7