10

С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
4

3 回答 3

2

要等待一个元素从 DOM 中消失,您需要先开始等待元素消失,然后再执行以下操作:

await Promise.all([
  await page.waitForSelector(waitingSpinner,{state: 'detached'}),
  await page.click('This is the element which causes the spinner to start')
]);
于 2021-07-26T20:18:22.707 回答
0

尝试这个:

等待 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');

这是 API 文档:https ://playwright.dev/docs/api/class-page#page-wait-for-selector

于 2021-11-24T22:47:01.333 回答
0

您可以从以下列表中一次选择多个项目:

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

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

于 2021-07-26T20:08:07.143 回答