mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: add log entry if selector resolves to multiple elements on click (#7623)
This commit is contained in:
parent
dd26529b3d
commit
cf0fb33540
@ -938,15 +938,19 @@ export function waitForSelectorTask(selector: SelectorInfo, state: 'attached' |
|
||||
let lastElement: Element | undefined;
|
||||
|
||||
return injected.pollRaf((progress, continuePolling) => {
|
||||
const element = injected.querySelector(parsed, root || document);
|
||||
const elements = injected.querySelectorAll(parsed, root || document);
|
||||
const element = elements[0];
|
||||
const visible = element ? injected.isVisible(element) : false;
|
||||
|
||||
if (lastElement !== element) {
|
||||
lastElement = element;
|
||||
if (!element)
|
||||
if (!element) {
|
||||
progress.log(` selector did not resolve to any element`);
|
||||
else
|
||||
} else {
|
||||
if (elements.length > 1)
|
||||
progress.log(` selector resolved to ${elements.length} elements. Proceeding with the first one.`);
|
||||
progress.log(` selector resolved to ${visible ? 'visible' : 'hidden'} ${injected.previewNode(element)}`);
|
||||
}
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
|
||||
@ -169,6 +169,22 @@ it('should report logs while waiting for hidden', async ({page, server}) => {
|
||||
expect(error.message).toContain(`selector resolved to visible <div class="another">hello</div>`);
|
||||
});
|
||||
|
||||
it('should report logs when the selector resolves to multiple elements', async ({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.setContent(`
|
||||
<button style="display: none; position: absolute; top: 0px; left: 0px; width: 100%;">
|
||||
Reset
|
||||
</button>
|
||||
<button>
|
||||
Reset
|
||||
</button>
|
||||
`);
|
||||
const error = await page.click('text=Reset', {
|
||||
timeout: 1000
|
||||
}).catch(e => e);
|
||||
expect(error.toString()).toContain('selector resolved to 2 elements. Proceeding with the first one.');
|
||||
});
|
||||
|
||||
it('should resolve promise when node is added in shadow dom', async ({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const watchdog = page.waitForSelector('span');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user