13

Сase: There is a list in which you need to select an item, then it closes. When you click on another item the list does not have time to close. Finally there is one more click on another list element.

await page.waitForSelector('.list');
await page.click('.list');
await page.waitForSelector('.list-element');
await page.click('.list-element'); // click on the list element and list closes
await page.click('.another-element'); // click on the list
theDavidBarton
  • 7,643
  • 4
  • 24
  • 51
Oleksiy
  • 131
  • 1
  • 3
  • Maybe [`page.select()`](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pageselectselector-values) or [`elementHandle.select()`](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#elementhandleselectvalues) can help? – vsemozhebuty May 26 '20 at 14:41
  • Could you check this https://stackoverflow.com/questions/61647401/puppeteer-does-not-change-selector/61658589#61658589 ? Maybe that helps – hardkoded May 26 '20 at 17:30
  • 10
    In playwright, you can use `page.waitForSelector(selector, {state: "detached"});` to wait for the element to be detached from the dom – arjunattam May 26 '20 at 23:09

3 Answers3

4

For waiting for an element to disappear from DOM, you need to start waiting first for the element to disappear before the action which makes it so:

await Promise.all([
  await page.waitForSelector(waitingSpinner,{state: 'detached'}),
  await page.click('This is the element which causes the spinner to start')
]);
Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23
0

You can select multiple items at once from a list as below:

// multiple selection
page.selectOption('select#colors', ['red', 'green', 'blue']);

Source: https://playwright.dev/docs/api/class-page#page-select-option

Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23
0

Try this:

await page.waitForSelector('.list', {state: 'hidden'});

await page.waitForSelector('.list');
await page.click('.list');
await page.waitForSelector('.list-element');
await page.click('.list-element');
await page.waitForSelector('.list', {state: 'hidden'});
await page.click('.another-element');

This is the API Documentation: https://playwright.dev/docs/api/class-page#page-wait-for-selector

javaLover
  • 31
  • 1
  • 4