fix(isVisible): do not wait for the selector to be resolved (#5393)
This commit is contained in:
parent
4d4efccb3e
commit
78ab2955f3
|
|
@ -723,7 +723,7 @@ Returns whether the element is [enabled](./actionability.md#enabled).
|
||||||
## async method: Frame.isHidden
|
## async method: Frame.isHidden
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
|
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered hidden.
|
||||||
|
|
||||||
### param: Frame.isHidden.selector = %%-input-selector-%%
|
### param: Frame.isHidden.selector = %%-input-selector-%%
|
||||||
|
|
||||||
|
|
@ -732,7 +732,7 @@ Returns whether the element is hidden, the opposite of [visible](./actionability
|
||||||
## async method: Frame.isVisible
|
## async method: Frame.isVisible
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
Returns whether the element is [visible](./actionability.md#visible).
|
Returns whether the element is [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered not visible.
|
||||||
|
|
||||||
### param: Frame.isVisible.selector = %%-input-selector-%%
|
### param: Frame.isVisible.selector = %%-input-selector-%%
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1448,7 +1448,7 @@ Returns whether the element is [enabled](./actionability.md#enabled).
|
||||||
## async method: Page.isHidden
|
## async method: Page.isHidden
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
|
Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered hidden.
|
||||||
|
|
||||||
### param: Page.isHidden.selector = %%-input-selector-%%
|
### param: Page.isHidden.selector = %%-input-selector-%%
|
||||||
|
|
||||||
|
|
@ -1457,7 +1457,7 @@ Returns whether the element is hidden, the opposite of [visible](./actionability
|
||||||
## async method: Page.isVisible
|
## async method: Page.isVisible
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
Returns whether the element is [visible](./actionability.md#visible).
|
Returns whether the element is [visible](./actionability.md#visible). [`option: selector`] that does not match any elements is considered not visible.
|
||||||
|
|
||||||
### param: Page.isVisible.selector = %%-input-selector-%%
|
### param: Page.isVisible.selector = %%-input-selector-%%
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -946,11 +946,10 @@ export class Frame extends SdkObject {
|
||||||
|
|
||||||
async isVisible(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {
|
async isVisible(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {
|
||||||
const controller = new ProgressController(metadata, this);
|
const controller = new ProgressController(metadata, this);
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
|
||||||
const task = dom.visibleTask(info);
|
|
||||||
return controller.run(async progress => {
|
return controller.run(async progress => {
|
||||||
progress.log(` checking visibility of "${selector}"`);
|
progress.log(` checking visibility of "${selector}"`);
|
||||||
return this._scheduleRerunnableTask(progress, info.world, task);
|
const element = await this.$(selector);
|
||||||
|
return element ? await element.isVisible() : false;
|
||||||
}, this._page._timeoutSettings.timeout(options));
|
}, this._page._timeoutSettings.timeout(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,16 +159,21 @@ it('getAttribute should be atomic', async ({ playwright, page }) => {
|
||||||
|
|
||||||
it('isVisible and isHidden should work', async ({ page }) => {
|
it('isVisible and isHidden should work', async ({ page }) => {
|
||||||
await page.setContent(`<div>Hi</div><span></span>`);
|
await page.setContent(`<div>Hi</div><span></span>`);
|
||||||
|
|
||||||
const div = await page.$('div');
|
const div = await page.$('div');
|
||||||
expect(await div.isVisible()).toBe(true);
|
expect(await div.isVisible()).toBe(true);
|
||||||
expect(await div.isHidden()).toBe(false);
|
expect(await div.isHidden()).toBe(false);
|
||||||
expect(await page.isVisible('div')).toBe(true);
|
expect(await page.isVisible('div')).toBe(true);
|
||||||
expect(await page.isHidden('div')).toBe(false);
|
expect(await page.isHidden('div')).toBe(false);
|
||||||
|
|
||||||
const span = await page.$('span');
|
const span = await page.$('span');
|
||||||
expect(await span.isVisible()).toBe(false);
|
expect(await span.isVisible()).toBe(false);
|
||||||
expect(await span.isHidden()).toBe(true);
|
expect(await span.isHidden()).toBe(true);
|
||||||
expect(await page.isVisible('span')).toBe(false);
|
expect(await page.isVisible('span')).toBe(false);
|
||||||
expect(await page.isHidden('span')).toBe(true);
|
expect(await page.isHidden('span')).toBe(true);
|
||||||
|
|
||||||
|
expect(await page.isVisible('no-such-element')).toBe(false);
|
||||||
|
expect(await page.isHidden('no-such-element')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('isEnabled and isDisabled should work', async ({ page }) => {
|
it('isEnabled and isDisabled should work', async ({ page }) => {
|
||||||
|
|
|
||||||
12
types/types.d.ts
vendored
12
types/types.d.ts
vendored
|
|
@ -2037,7 +2037,8 @@ export interface Page {
|
||||||
}): Promise<boolean>;
|
}): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible).
|
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
|
||||||
|
* match any elements is considered hidden.
|
||||||
* @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://playwright.dev/docs/selectors) for more details.
|
* @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://playwright.dev/docs/selectors) for more details.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
|
|
@ -2052,7 +2053,8 @@ export interface Page {
|
||||||
}): Promise<boolean>;
|
}): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible).
|
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
|
||||||
|
* considered not visible.
|
||||||
* @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://playwright.dev/docs/selectors) for more details.
|
* @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://playwright.dev/docs/selectors) for more details.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
|
|
@ -3992,7 +3994,8 @@ export interface Frame {
|
||||||
}): Promise<boolean>;
|
}): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible).
|
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
|
||||||
|
* match any elements is considered hidden.
|
||||||
* @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://playwright.dev/docs/selectors) for more details.
|
* @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://playwright.dev/docs/selectors) for more details.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
|
|
@ -4007,7 +4010,8 @@ export interface Frame {
|
||||||
}): Promise<boolean>;
|
}): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible).
|
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
|
||||||
|
* considered not visible.
|
||||||
* @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://playwright.dev/docs/selectors) for more details.
|
* @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://playwright.dev/docs/selectors) for more details.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue