Skip to content

Commit a6f62f1

Browse files
authored
fix(isVisible): do not wait for the selector to be resolved (#5393) (#5398)
1 parent a1c6ab2 commit a6f62f1

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

docs/src/api/class-frame.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ Returns whether the element is [enabled](./actionability.md#enabled).
761761
## async method: Frame.isHidden
762762
- returns: <[boolean]>
763763

764-
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
764+
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered hidden.
765765

766766
### param: Frame.isHidden.selector = %%-input-selector-%%
767767

@@ -770,7 +770,7 @@ Returns whether the element is hidden, the opposite of [visible](./actionability
770770
## async method: Frame.isVisible
771771
- returns: <[boolean]>
772772

773-
Returns whether the element is [visible](./actionability.md#visible).
773+
Returns whether the element is [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered not visible.
774774

775775
### param: Frame.isVisible.selector = %%-input-selector-%%
776776

docs/src/api/class-page.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ Returns whether the element is [enabled](./actionability.md#enabled).
14771477
## async method: Page.isHidden
14781478
- returns: <[boolean]>
14791479

1480-
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
1480+
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered hidden.
14811481

14821482
### param: Page.isHidden.selector = %%-input-selector-%%
14831483

@@ -1486,7 +1486,7 @@ Returns whether the element is hidden, the opposite of [visible](./actionability
14861486
## async method: Page.isVisible
14871487
- returns: <[boolean]>
14881488

1489-
Returns whether the element is [visible](./actionability.md#visible).
1489+
Returns whether the element is [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered not visible.
14901490

14911491
### param: Page.isVisible.selector = %%-input-selector-%%
14921492

src/server/frames.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,10 @@ export class Frame extends EventEmitter {
928928
}
929929

930930
async isVisible(selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {
931-
const info = this._page.selectors._parseSelector(selector);
932-
const task = dom.visibleTask(info);
933931
return runAbortableTask(async progress => {
934932
progress.log(` checking visibility of "${selector}"`);
935-
return this._scheduleRerunnableTask(progress, info.world, task);
933+
const element = await this.$(selector);
934+
return element ? await element.isVisible() : false;
936935
}, this._page._timeoutSettings.timeout(options));
937936
}
938937

test/elementhandle-convenience.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,21 @@ it('getAttribute should be atomic', async ({ playwright, page }) => {
159159

160160
it('isVisible and isHidden should work', async ({ page }) => {
161161
await page.setContent(`<div>Hi</div><span></span>`);
162+
162163
const div = await page.$('div');
163164
expect(await div.isVisible()).toBe(true);
164165
expect(await div.isHidden()).toBe(false);
165166
expect(await page.isVisible('div')).toBe(true);
166167
expect(await page.isHidden('div')).toBe(false);
168+
167169
const span = await page.$('span');
168170
expect(await span.isVisible()).toBe(false);
169171
expect(await span.isHidden()).toBe(true);
170172
expect(await page.isVisible('span')).toBe(false);
171173
expect(await page.isHidden('span')).toBe(true);
174+
175+
expect(await page.isVisible('no-such-element')).toBe(false);
176+
expect(await page.isHidden('no-such-element')).toBe(true);
172177
});
173178

174179
it('isEnabled and isDisabled should work', async ({ page }) => {

types/types.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,8 @@ export interface Page {
20282028
}): Promise<boolean>;
20292029

20302030
/**
2031-
* Returns whether the element is hidden, the opposite of [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible).
2031+
* Returns whether the element is hidden, the opposite of [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible). `selector` that does not
2032+
* match any elements is considered hidden.
20322033
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://github.com/microsoft/playwright/blob/master/docs/selectors.md#working-with-selectors) for more details.
20332034
* @param options
20342035
*/
@@ -2044,7 +2045,8 @@ export interface Page {
20442045
}): Promise<boolean>;
20452046

20462047
/**
2047-
* Returns whether the element is [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible).
2048+
* Returns whether the element is [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible). `selector` that does not match any elements is
2049+
* considered not visible.
20482050
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://github.com/microsoft/playwright/blob/master/docs/selectors.md#working-with-selectors) for more details.
20492051
* @param options
20502052
*/
@@ -3992,7 +3994,8 @@ export interface Frame {
39923994
}): Promise<boolean>;
39933995

39943996
/**
3995-
* Returns whether the element is hidden, the opposite of [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible).
3997+
* Returns whether the element is hidden, the opposite of [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible). `selector` that does not
3998+
* match any elements is considered hidden.
39963999
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://github.com/microsoft/playwright/blob/master/docs/selectors.md#working-with-selectors) for more details.
39974000
* @param options
39984001
*/
@@ -4008,7 +4011,8 @@ export interface Frame {
40084011
}): Promise<boolean>;
40094012

40104013
/**
4011-
* Returns whether the element is [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible).
4014+
* Returns whether the element is [visible](https://github.com/microsoft/playwright/blob/master/docs/actionability.md#visible). `selector` that does not match any elements is
4015+
* considered not visible.
40124016
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://github.com/microsoft/playwright/blob/master/docs/selectors.md#working-with-selectors) for more details.
40134017
* @param options
40144018
*/

0 commit comments

Comments
 (0)