Puppeteer:我怎样才能等到列表关闭?如何等到元素从 DOM 中消失?

Ole*_*siy 5 puppeteer playwright

?ase: 有一个列表,您需要在其中选择一个项目,然后关闭。当您单击另一个项目时,列表没有时间关闭。最后,再次单击另一个列表元素。

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
Run Code Online (Sandbox Code Playgroud)

Vis*_*wal 4

为了等待一个元素从 DOM 中消失,你需要先开始等待该元素消失,然后再执行使其消失的操作:

await Promise.all([
  await page.waitForSelector(waitingSpinner,{state: 'detached'}),
  await page.click('This is the element which causes the spinner to start')
]);
Run Code Online (Sandbox Code Playgroud)