diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 537f39296a..11180aee28 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -898,47 +898,37 @@ For example, `article` that has `text=Playwright` matches `
Playwri Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. ## locator-option-left-of -- `leftOf` <[Locator]|[Object]> - - `locator` <[Locator]> The inner locator. - - `maxDistance` ?<[float]> Maximum horizontal distance between the elements in pixels, unlimited by default. +- `leftOf` <[Locator]> Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator is queried against the same root as the outer one. More details in [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. ## locator-option-right-of -- `rightOf` <[Locator]|[Object]> - - `locator` <[Locator]> The inner locator. - - `maxDistance` ?<[float]> Maximum horizontal distance between the elements in pixels, unlimited by default. +- `rightOf` <[Locator]> Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner locator is queried against the same root as the outer one. More details in [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. ## locator-option-above -- `above` <[Locator]|[Object]> - - `locator` <[Locator]> The inner locator. - - `maxDistance` ?<[float]> Maximum vertical distance between the elements in pixels, unlimited by default. +- `above` <[Locator]> Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner locator is queried against the same root as the outer one. More details in [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. ## locator-option-below -- `below` <[Locator]|[Object]> - - `locator` <[Locator]> The inner locator. - - `maxDistance` ?<[float]> Maximum vertical distance between the elements in pixels, unlimited by default. +- `below` <[Locator]> Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner locator is queried against the same root as the outer one. More details in [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. ## locator-option-near -- `near` <[Locator]|[Object]> - - `locator` <[Locator]> The inner locator. - - `maxDistance` ?<[float]> Maximum distance between the elements in pixels, 50 by default. +- `near` <[Locator]> -Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same root as the outer one. More details in [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. +Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is queried against the same root as the outer one. More details in [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts index 936d39cace..5f8bd4c1d4 100644 --- a/packages/playwright-core/src/client/locator.ts +++ b/packages/playwright-core/src/client/locator.ts @@ -29,11 +29,11 @@ import { escapeWithQuotes } from '../utils/isomorphic/stringUtils'; export type LocatorOptions = { hasText?: string | RegExp; has?: Locator; - leftOf?: Locator | { locator: Locator, maxDistance?: number }; - rightOf?: Locator | { locator: Locator, maxDistance?: number }; - above?: Locator | { locator: Locator, maxDistance?: number }; - below?: Locator | { locator: Locator, maxDistance?: number }; - near?: Locator | { locator: Locator, maxDistance?: number }; + leftOf?: Locator; + rightOf?: Locator; + above?: Locator; + below?: Locator; + near?: Locator; }; export class Locator implements api.Locator { @@ -52,30 +52,14 @@ export class Locator implements api.Locator { this._selector += ` >> :scope:has-text(${escapeWithQuotes(text, '"')})`; } - if (options?.has) { - if (options.has._frame !== frame) - throw new Error(`Inner "has" locator must belong to the same frame.`); - this._selector += ` >> has=` + JSON.stringify(options.has._selector); - } - - for (const inner of ['leftOf', 'rightOf', 'above', 'below', 'near'] as const) { - const value = options?.[inner]; - if (!value) + for (const inner of ['has', 'leftOf', 'rightOf', 'above', 'below', 'near'] as const) { + const locator = options?.[inner]; + if (!locator) continue; - let maxDistance: number | undefined; - let locator: Locator; - if (value instanceof Locator) { - locator = value; - } else { - locator = value.locator; - maxDistance = value.maxDistance; - } if (locator._frame !== frame) throw new Error(`Inner "${inner}" locator must belong to the same frame.`); - if (maxDistance !== undefined && typeof maxDistance !== 'number') - throw new Error(`"${inner}.maxDistance" must be a number, found ${typeof maxDistance}.`); const engineName = inner === 'leftOf' ? 'left-of' : (inner === 'rightOf' ? 'right-of' : inner); - this._selector += ` >> ${engineName}=` + JSON.stringify(locator._selector) + (maxDistance === undefined ? '' : ',' + maxDistance); + this._selector += ` >> ${engineName}=` + JSON.stringify(locator._selector); } } diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 003b8107b5..71d15d0b7a 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -2626,17 +2626,7 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -2645,17 +2635,7 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -2679,35 +2659,16 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -2716,17 +2677,7 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -5544,17 +5495,7 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -5563,17 +5504,7 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -5597,35 +5528,16 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -5634,17 +5546,7 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -9612,17 +9514,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -9631,17 +9523,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -9665,35 +9547,16 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -9702,17 +9565,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -10101,17 +9954,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -10120,17 +9963,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -10154,35 +9987,16 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -10191,17 +10005,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -14306,17 +14110,7 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -14325,17 +14119,7 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -14359,35 +14143,16 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -14396,17 +14161,7 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** diff --git a/tests/config/experimental.d.ts b/tests/config/experimental.d.ts index f10f8895d8..52d1679db1 100644 --- a/tests/config/experimental.d.ts +++ b/tests/config/experimental.d.ts @@ -2628,17 +2628,7 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -2647,17 +2637,7 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -2681,35 +2661,16 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -2718,17 +2679,7 @@ export interface Page { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -5546,17 +5497,7 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -5565,17 +5506,7 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -5599,35 +5530,16 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -5636,17 +5548,7 @@ export interface Frame { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -9614,17 +9516,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -9633,17 +9525,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -9667,35 +9549,16 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -9704,17 +9567,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -10103,17 +9956,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -10122,17 +9965,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -10156,35 +9989,16 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -10193,17 +10007,7 @@ export interface Locator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** @@ -14308,17 +14112,7 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - above?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + above?: Locator; /** * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner @@ -14327,17 +14121,7 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - below?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum vertical distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + below?: Locator; /** * Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. @@ -14361,35 +14145,16 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - leftOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + leftOf?: Locator; /** - * Matches elements that are near any of the elements matching the inner locator. Inner locator is queried against the same - * root as the outer one. More details in [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. + * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is + * queried against the same root as the outer one. More details in + * [layout selectors](https://playwright.dev/docs/selectors#selecting-elements-based-on-layout) guide. * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - near?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum distance between the elements in pixels, 50 by default. - */ - maxDistance?: number; - }; + near?: Locator; /** * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner @@ -14398,17 +14163,7 @@ export interface FrameLocator { * * Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. */ - rightOf?: Locator|{ - /** - * The inner locator. - */ - locator: Locator; - - /** - * Maximum horizontal distance between the elements in pixels, unlimited by default. - */ - maxDistance?: number; - }; + rightOf?: Locator; }): Locator; /** diff --git a/tests/page/locator-query.spec.ts b/tests/page/locator-query.spec.ts index 3c3015ba36..e1a6b67a9e 100644 --- a/tests/page/locator-query.spec.ts +++ b/tests/page/locator-query.spec.ts @@ -154,13 +154,3 @@ it('should enforce same frame for has/leftOf/rightOf/above/below/near', async ({ expect(error.message).toContain(`Inner "${option}" locator must belong to the same frame.`); } }); - -it('should check leftOf options', async ({ page }) => { - let error; - try { - page.locator('div', { leftOf: { locator: page.locator('span'), maxDistance: 'abc' } as any }); - } catch (e) { - error = e; - } - expect(error.message).toContain(`"leftOf.maxDistance" must be a number, found string.`); -}); diff --git a/tests/page/selectors-misc.spec.ts b/tests/page/selectors-misc.spec.ts index 0a10b43614..528e5f1b79 100644 --- a/tests/page/selectors-misc.spec.ts +++ b/tests/page/selectors-misc.spec.ts @@ -241,15 +241,9 @@ it('should work with layout selectors', async ({ page, trace }) => { expect(await page.$$eval('div:right-of(#id3, 50)', els => els.map(e => e.id).join(','))).toBe('id2,id5,id7,id8'); expect(await page.$$eval('div >> right-of="#id3",50', els => els.map(e => e.id).join(','))).toBe('id2,id5,id7,id8'); expect(await page.$$eval('div >> right-of="#id3",50 >> span', els => els.map(e => e.textContent).join(','))).toBe('2,5,7,8'); - expect(await page.locator('div', { - rightOf: { locator: page.locator('#id3'), maxDistance: 50 }, - }).locator('span').evaluateAll(els => els.map(e => e.textContent).join(','))).toBe('2,5,7,8'); expect(await page.$$eval('div:right-of(#id3, 49)', els => els.map(e => e.id).join(','))).toBe('id7,id8'); expect(await page.$$eval('div >> right-of="#id3",49', els => els.map(e => e.id).join(','))).toBe('id7,id8'); expect(await page.$$eval('div >> right-of="#id3",49 >> span', els => els.map(e => e.textContent).join(','))).toBe('7,8'); - expect(await page.locator('div', { - rightOf: { locator: page.locator('#id3'), maxDistance: 49 }, - }).locator('span').evaluateAll(els => els.map(e => e.textContent).join(','))).toBe('7,8'); expect(await page.$eval('div:left-of(#id2)', e => e.id)).toBe('id1'); expect(await page.$eval('div >> left-of="#id2"', e => e.id)).toBe('id1');