fix(selectors): combine visible with other selectors (#9585)

This commit is contained in:
Yury Semikhatsky 2021-10-18 10:47:37 -07:00 committed by GitHub
parent 3d14c1ff51
commit fd81982c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -154,7 +154,8 @@ export class InjectedScript {
if (part.name === 'visible') {
const visible = Boolean(part.body);
return roots.filter(match => visible === isVisible(match.element));
const filtered = roots.filter(match => visible === isVisible(match.element));
return this._querySelectorRecursively(filtered, selector, index + 1, queryCache);
}
const result: ElementMatch[] = [];

View File

@ -99,3 +99,18 @@ it('should waitFor hidden', async ({ page }) => {
await page.$eval('div', div => div.innerHTML = '');
await promise;
});
it('should combine visible with other selectors', async ({ page }) => {
page.on('console', m => console.log(m.text()));
await page.setContent(`<div>
<div class="item" style="display: none">Hidden data0</div>
<div class="item">visible data1</div>
<div class="item" style="display: none">Hidden data1</div>
<div class="item">visible data2</div>
<div class="item" style="display: none">Hidden data1</div>
<div class="item">visible data3</div>
</div>`);
const locator = page.locator('.item >> visible=true').nth(1);
await expect(locator).toHaveText('visible data2');
await expect(page.locator('.item >> visible=true >> text=data3')).toHaveText('visible data3');
});