@types/k6 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. k6/README.md +2 -2
  2. k6/browser/index.d.ts +1414 -260
  3. k6/package.json +7 -2
k6/browser/index.d.ts CHANGED
@@ -1719,10 +1719,18 @@ export interface Frame {
1719
1719
 
1720
1720
  /**
1721
1721
  * Сreates and returns a new locator for this frame.
1722
+ *
1723
+ * @example
1724
+ * ```js
1725
+ * const frame = page.frames()[1];
1726
+ * const submitButton = frame.locator('button', { hasText: 'Pizza, Please!' });
1727
+ * ```
1728
+ *
1722
1729
  * @param selector The selector to use.
1730
+ * @param options Options to use for filtering.
1723
1731
  * @returns The new locator.
1724
1732
  */
1725
- locator(selector: string): Locator;
1733
+ locator(selector: string, options?: LocatorOptions): Locator;
1726
1734
 
1727
1735
  /**
1728
1736
  * Get the `innerHTML` attribute of the first element found that matches the selector.
@@ -1961,132 +1969,859 @@ export interface Frame {
1961
1969
  * @param timeout The timeout to wait for.
1962
1970
  */
1963
1971
  waitForTimeout(timeout: number): Promise<void>;
1964
- }
1965
-
1966
- /**
1967
- * JSHandle represents an in-page JavaScript object.
1968
- */
1969
- export interface JSHandle<T = any> {
1970
- /**
1971
- * Returns either `null` or the object handle itself, if the object handle is
1972
- * an instance of `ElementHandle`.
1973
- * @returns The ElementHandle if available.
1974
- */
1975
- asElement(): Promise<ElementHandle | null>;
1976
-
1977
- /**
1978
- * Stops referencing the element handle.
1979
- */
1980
- dispose(): Promise<void>;
1981
1972
 
1982
1973
  /**
1983
- * Evaluates the page function and returns its return value.
1984
- * This method passes this handle as the first argument to the page function.
1985
- * @param pageFunction The function to be evaluated.
1986
- * @param args The arguments to pass to the page function.
1987
- * @returns The return value of `pageFunction`.
1974
+ * Returns {@link Locator} to the element with the corresponding role.
1975
+ *
1976
+ * @example
1977
+ * ```js
1978
+ * const locator = frame.getByRole('button', { name: 'Pizza, Please!' });
1979
+ *
1980
+ * await locator.click();
1981
+ * ```
1982
+ *
1983
+ * @param role The role of the element.
1984
+ * @param options Options to use.
1985
+ * @returns The locator to the element with the corresponding role.
1988
1986
  */
1989
- evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg?: Arg): Promise<R>;
1987
+ getByRole(
1988
+ role:
1989
+ | "alert"
1990
+ | "alertdialog"
1991
+ | "application"
1992
+ | "article"
1993
+ | "banner"
1994
+ | "blockquote"
1995
+ | "button"
1996
+ | "caption"
1997
+ | "cell"
1998
+ | "checkbox"
1999
+ | "code"
2000
+ | "columnheader"
2001
+ | "combobox"
2002
+ | "complementary"
2003
+ | "contentinfo"
2004
+ | "definition"
2005
+ | "dialog"
2006
+ | "directory"
2007
+ | "document"
2008
+ | "emphasis"
2009
+ | "feed"
2010
+ | "figure"
2011
+ | "form"
2012
+ | "generic"
2013
+ | "grid"
2014
+ | "gridcell"
2015
+ | "group"
2016
+ | "heading"
2017
+ | "img"
2018
+ | "insertion"
2019
+ | "link"
2020
+ | "list"
2021
+ | "listbox"
2022
+ | "listitem"
2023
+ | "log"
2024
+ | "main"
2025
+ | "marquee"
2026
+ | "math"
2027
+ | "menu"
2028
+ | "menubar"
2029
+ | "menuitem"
2030
+ | "menuitemcheckbox"
2031
+ | "menuitemradio"
2032
+ | "meter"
2033
+ | "navigation"
2034
+ | "none"
2035
+ | "note"
2036
+ | "option"
2037
+ | "presentation"
2038
+ | "progressbar"
2039
+ | "radio"
2040
+ | "radiogroup"
2041
+ | "region"
2042
+ | "row"
2043
+ | "rowgroup"
2044
+ | "rowheader"
2045
+ | "scrollbar"
2046
+ | "search"
2047
+ | "searchbox"
2048
+ | "separator"
2049
+ | "slider"
2050
+ | "spinbutton"
2051
+ | "status"
2052
+ | "strong"
2053
+ | "subscript"
2054
+ | "superscript"
2055
+ | "switch"
2056
+ | "tab"
2057
+ | "table"
2058
+ | "tablist"
2059
+ | "tabpanel"
2060
+ | "term"
2061
+ | "textbox"
2062
+ | "time"
2063
+ | "timer"
2064
+ | "toolbar"
2065
+ | "tooltip"
2066
+ | "tree"
2067
+ | "treegrid"
2068
+ | "treeitem",
2069
+ options?: {
2070
+ /**
2071
+ * Whether the accessible `options.name` should be checked exactly for equality.
2072
+ *
2073
+ * @defaultValue false
2074
+ */
2075
+ exact?: boolean;
1990
2076
 
1991
- /**
1992
- * Evaluates the page function and returns a `JSHandle`.
1993
- * This method passes this handle as the first argument to the page function.
1994
- * Unlike `evaluate`, `evaluateHandle` returns the value as a `JSHandle`
1995
- * @param pageFunction The function to be evaluated.
1996
- * @param args The arguments to pass to the page function.
1997
- * @returns A JSHandle of the return value of `pageFunction`.
1998
- */
1999
- evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg?: Arg): Promise<JSHandle<R>>;
2077
+ /**
2078
+ * Whether to include elements that are normally excluded from the accessibility tree.
2079
+ *
2080
+ * @defaultValue false
2081
+ */
2082
+ includeHidden?: boolean;
2000
2083
 
2001
- /**
2002
- * Fetches a map with own property names of of the `JSHandle` with their values as
2003
- * `JSHandle` instances.
2004
- * @returns A map with property names as keys and `JSHandle` instances for the property values.
2005
- */
2006
- getProperties(): Promise<Map<string, JSHandle>>;
2084
+ /**
2085
+ * A number attribute that is traditionally used for headings h1-h6.
2086
+ */
2087
+ level?: number;
2007
2088
 
2008
- /**
2009
- * Fetches a JSON representation of the object.
2010
- * @returns A JSON representation of the object.
2011
- */
2012
- jsonValue(): Promise<any>;
2013
- }
2089
+ /**
2090
+ * An accessible name for the element, such as a text in a button or a label for an input.
2091
+ */
2092
+ name?: string | RegExp;
2014
2093
 
2015
- /**
2016
- * Keyboard provides an API for managing a virtual keyboard.
2017
- */
2018
- export interface Keyboard {
2019
- /**
2020
- * Sends a key down message to a session target.
2021
- * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
2022
- * @param key Name of key to press, such as `ArrowLeft`.
2023
- */
2024
- down(key: string): Promise<void>;
2094
+ /**
2095
+ * A boolean attribute that can be used to indicate if a checkbox is checked or not.
2096
+ */
2097
+ checked?: boolean;
2025
2098
 
2026
- /**
2027
- * Dispatches an `input` event with the given `text`.
2028
- * This method does not emit `keyDown`, `keyUp` or `keyPress` events.
2029
- * @param text Event text.
2030
- */
2031
- insertText(text: string): Promise<void>;
2099
+ /**
2100
+ * A boolean attribute that can be used to indicate if an element is disabled or not.
2101
+ */
2102
+ disabled?: boolean;
2032
2103
 
2033
- /**
2034
- * Sends a key press message to a session target.
2035
- * A press message consists of successive key down and up messages.
2036
- * @param key Sequence of keys to press.
2037
- * @param options Specifies the typing options.
2038
- */
2039
- press(key: string, options?: { delay?: number }): Promise<void>;
2104
+ /**
2105
+ * A boolean attribute that can be used to indicate if an element is expanded or not.
2106
+ */
2107
+ expanded?: boolean;
2040
2108
 
2041
- /**
2042
- * Type sends a `press` message to a session target for each character in text.
2043
- * It sends an insertText message if a character is not among
2044
- * valid characters in the keyboard's layout.
2045
- * Modifier keys `Shift`, `Control`, `Alt`, `Meta` are _not_ respected.
2046
- * @param text A text to type into a focused element.
2047
- * @param options Specifies the typing options.
2048
- */
2049
- type(text: string, options?: { delay?: number }): Promise<void>;
2109
+ /**
2110
+ * A boolean attribute that can be used to indicate if an element is pressed or not.
2111
+ */
2112
+ pressed?: boolean;
2050
2113
 
2051
- /**
2052
- * Sends a key up message to a session target.
2053
- * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
2054
- * @param key Name of key to release, such as `ArrowLeft`.
2055
- */
2056
- up(key: string): Promise<void>;
2057
- }
2114
+ /**
2115
+ * A boolean attribute that can be used to indicate if an element is selected or not.
2116
+ */
2117
+ selected?: boolean;
2118
+ },
2119
+ ): Locator;
2058
2120
 
2059
- /**
2060
- * The Locator API makes it easier to work with dynamically changing elements.
2061
- * Some of the benefits of using it over existing ways to locate an element
2062
- * (e.g. Page.$()) include:
2063
- *
2064
- * - Helps with writing robust tests by finding an element even if the
2065
- * underlying frame navigates.
2066
- * - Makes it easier to work with dynamic web pages and SPAs built with Svelte,
2067
- * React, Vue, etc.
2068
- */
2069
- export interface Locator {
2070
2121
  /**
2071
- * Returns an array of locators matching the selector.
2072
- *
2073
- * **Usage**
2122
+ * Returns {@link Locator} to the element with the corresponding alt text.
2074
2123
  *
2124
+ * @example
2075
2125
  * ```js
2076
- * // Select all options
2077
- * for (const option of await page.locator('option').all())
2078
- * await option.click();
2126
+ * const locator = frame.getByAltText('pizza');
2127
+ *
2128
+ * await locator.click();
2079
2129
  * ```
2080
2130
  *
2081
- * @returns Array of locators
2131
+ * @param altText The alt text of the element.
2132
+ * @param options Options to use.
2133
+ * @returns The locator to the element with the corresponding alt text.
2082
2134
  */
2083
- all(): Promise<Locator[]>;
2084
-
2085
- /**
2086
- * Clears text boxes and input fields of any existing values.
2087
- *
2088
- * **Usage**
2089
- *
2135
+ getByAltText(
2136
+ altText: string | RegExp,
2137
+ options?: {
2138
+ /**
2139
+ * Whether the locator should be exact.
2140
+ *
2141
+ * @defaultValue false
2142
+ */
2143
+ exact?: boolean;
2144
+ },
2145
+ ): Locator;
2146
+
2147
+ /**
2148
+ * Returns {@link Locator} to the element with the corresponding label text.
2149
+ *
2150
+ * @example
2151
+ * ```js
2152
+ * const locator = frame.getByLabel('Password');
2153
+ *
2154
+ * await locator.fill('my-password');
2155
+ * ```
2156
+ *
2157
+ * @param label The label text of the element.
2158
+ * @param options Options to use.
2159
+ * @returns The locator to the element with the corresponding label text.
2160
+ */
2161
+ getByLabel(
2162
+ label: string | RegExp,
2163
+ options?: {
2164
+ /**
2165
+ * Whether the locator should be exact.
2166
+ *
2167
+ * @defaultValue false
2168
+ */
2169
+ exact?: boolean;
2170
+ },
2171
+ ): Locator;
2172
+
2173
+ /**
2174
+ * Allows locating elements by their text content. Returns {@link Locator}.
2175
+ *
2176
+ * Consider the following DOM structure:
2177
+ *
2178
+ * ```html
2179
+ * <div>Hello <span>world</span></div>
2180
+ * <div>Hello</div>
2181
+ * ```
2182
+ *
2183
+ * You can locate by text substring, exact string, or a regular expression:
2184
+ *
2185
+ * @example
2186
+ * ```js
2187
+ * // Matches <span>
2188
+ * frame.getByText('world');
2189
+ *
2190
+ * // Matches first <div>
2191
+ * frame.getByText('Hello world');
2192
+ *
2193
+ * // Matches second <div>
2194
+ * frame.getByText('Hello', { exact: true });
2195
+ *
2196
+ * // Matches both <div>s
2197
+ * frame.getByText(/Hello/);
2198
+ *
2199
+ * // Matches second <div>
2200
+ * frame.getByText(/^hello$/i);
2201
+ * ```
2202
+ *
2203
+ * Matching by text always normalizes whitespace, even with exact match. For
2204
+ * example, it turns multiple spaces into one, turns line breaks into spaces
2205
+ * and ignores leading and trailing whitespace.
2206
+ *
2207
+ * Input elements of the type `button` and `submit` are matched by their
2208
+ * `value` instead of the text content. For example, locating by text
2209
+ * `"Log in"` matches `<input type=button value="Log in">`.
2210
+ *
2211
+ * @param text Text to locate the element by.
2212
+ * @param options Options to use.
2213
+ * @returns The locator to the element with the corresponding text content.
2214
+ */
2215
+ getByText(
2216
+ text: string | RegExp,
2217
+ options?: {
2218
+ /**
2219
+ * Whether to find an exact match: case-sensitive and whole-string.
2220
+ * Default to false. Ignored when locating by a regular expression.
2221
+ * Note that exact match still trims whitespace.
2222
+ *
2223
+ * @defaultValue false
2224
+ */
2225
+ exact?: boolean;
2226
+ },
2227
+ ): Locator;
2228
+
2229
+ /**
2230
+ * Returns {@link Locator} to the element with the corresponding test ID.
2231
+ * Note that this method only supports the `data-testid` attribute.
2232
+ *
2233
+ * @example
2234
+ * HTML:
2235
+ * ```html
2236
+ * <button data-testid="submit-button">Submit</button>
2237
+ * ```
2238
+ *
2239
+ * JavaScript:
2240
+ * ```js
2241
+ * const locator = frame.getByTestId('submit-button');
2242
+ *
2243
+ * await locator.click();
2244
+ * ```
2245
+ *
2246
+ * @param testId The test ID of the element.
2247
+ * @returns The locator to the element with the corresponding test ID.
2248
+ */
2249
+ getByTestId(testId: string | RegExp): Locator;
2250
+
2251
+ /**
2252
+ * Returns {@link Locator} to the element with the corresponding placeholder text.
2253
+ *
2254
+ * @example
2255
+ * ```js
2256
+ * const locator = frame.getByPlaceholder('name@example.com');
2257
+ *
2258
+ * await locator.fill('my.name@example.com');
2259
+ * ```
2260
+ *
2261
+ * @param placeholder The placeholder text of the element.
2262
+ * @param options Options to use.
2263
+ * @returns The locator to the element with the corresponding placeholder text.
2264
+ */
2265
+ getByPlaceholder(
2266
+ placeholder: string | RegExp,
2267
+ options?: {
2268
+ /**
2269
+ * Whether the locator should be exact.
2270
+ *
2271
+ * @defaultValue false
2272
+ */
2273
+ exact?: boolean;
2274
+ },
2275
+ ): Locator;
2276
+
2277
+ /**
2278
+ * Returns {@link Locator} to the element with the corresponding title text.
2279
+ *
2280
+ * @example
2281
+ * ```js
2282
+ * const locator = frame.getByTitle('Information box');
2283
+ *
2284
+ * await locator.click();
2285
+ * ```
2286
+ *
2287
+ * @param title The title text of the element.
2288
+ * @param options Options to use.
2289
+ * @returns The locator to the element with the corresponding title text.
2290
+ */
2291
+ getByTitle(
2292
+ title: string | RegExp,
2293
+ options?: {
2294
+ /**
2295
+ * Whether the locator should be exact.
2296
+ *
2297
+ * @defaultValue false
2298
+ */
2299
+ exact?: boolean;
2300
+ },
2301
+ ): Locator;
2302
+ }
2303
+
2304
+ /**
2305
+ * FrameLocator makes it easier to locate elements within an `iframe` on the
2306
+ * page. `FrameLocator` are created by calling `page.locator(selector).contentFrame()`.
2307
+ * It works in the same way as `Locator` instances.
2308
+ */
2309
+ export interface FrameLocator {
2310
+ /**
2311
+ * The method finds all elements matching the selector and creates a new
2312
+ * locator that matches all of them. This method can be used to further
2313
+ * refine the locator by chaining additional selectors.
2314
+ *
2315
+ * @example
2316
+ * ```js
2317
+ * const frame = page.frameLocator('iframe');
2318
+ * const rows = frame.locator('table tr');
2319
+ * const cell = rows.locator('.selected');
2320
+ *
2321
+ * // Use with options to filter by text
2322
+ * const submitButton = frame.locator('button', { hasText: 'Submit' });
2323
+ * ```
2324
+ *
2325
+ * @param selector A selector to use when resolving DOM element.
2326
+ * @param options Options to use for filtering.
2327
+ * @returns The new locator.
2328
+ */
2329
+ locator(selector: string, options?: LocatorOptions): Locator;
2330
+
2331
+ /**
2332
+ * Returns {@link Locator} to the element with the corresponding role.
2333
+ *
2334
+ * @example
2335
+ * ```js
2336
+ * const locator = frameLocator.getByRole('button', { name: 'Pizza, Please!' });
2337
+ *
2338
+ * await locator.click();
2339
+ * ```
2340
+ *
2341
+ * @param role The role of the element.
2342
+ * @param options Options to use.
2343
+ * @returns The locator to the element with the corresponding role.
2344
+ */
2345
+ getByRole(
2346
+ role:
2347
+ | "alert"
2348
+ | "alertdialog"
2349
+ | "application"
2350
+ | "article"
2351
+ | "banner"
2352
+ | "blockquote"
2353
+ | "button"
2354
+ | "caption"
2355
+ | "cell"
2356
+ | "checkbox"
2357
+ | "code"
2358
+ | "columnheader"
2359
+ | "combobox"
2360
+ | "complementary"
2361
+ | "contentinfo"
2362
+ | "definition"
2363
+ | "dialog"
2364
+ | "directory"
2365
+ | "document"
2366
+ | "emphasis"
2367
+ | "feed"
2368
+ | "figure"
2369
+ | "form"
2370
+ | "generic"
2371
+ | "grid"
2372
+ | "gridcell"
2373
+ | "group"
2374
+ | "heading"
2375
+ | "img"
2376
+ | "insertion"
2377
+ | "link"
2378
+ | "list"
2379
+ | "listbox"
2380
+ | "listitem"
2381
+ | "log"
2382
+ | "main"
2383
+ | "marquee"
2384
+ | "math"
2385
+ | "menu"
2386
+ | "menubar"
2387
+ | "menuitem"
2388
+ | "menuitemcheckbox"
2389
+ | "menuitemradio"
2390
+ | "meter"
2391
+ | "navigation"
2392
+ | "none"
2393
+ | "note"
2394
+ | "option"
2395
+ | "presentation"
2396
+ | "progressbar"
2397
+ | "radio"
2398
+ | "radiogroup"
2399
+ | "region"
2400
+ | "row"
2401
+ | "rowgroup"
2402
+ | "rowheader"
2403
+ | "scrollbar"
2404
+ | "search"
2405
+ | "searchbox"
2406
+ | "separator"
2407
+ | "slider"
2408
+ | "spinbutton"
2409
+ | "status"
2410
+ | "strong"
2411
+ | "subscript"
2412
+ | "superscript"
2413
+ | "switch"
2414
+ | "tab"
2415
+ | "table"
2416
+ | "tablist"
2417
+ | "tabpanel"
2418
+ | "term"
2419
+ | "textbox"
2420
+ | "time"
2421
+ | "timer"
2422
+ | "toolbar"
2423
+ | "tooltip"
2424
+ | "tree"
2425
+ | "treegrid"
2426
+ | "treeitem",
2427
+ options?: {
2428
+ /**
2429
+ * Whether the accessible `options.name` should be checked exactly for equality.
2430
+ *
2431
+ * @defaultValue false
2432
+ */
2433
+ exact?: boolean;
2434
+
2435
+ /**
2436
+ * Whether to include elements that are normally excluded from the accessibility tree.
2437
+ *
2438
+ * @defaultValue false
2439
+ */
2440
+ includeHidden?: boolean;
2441
+
2442
+ /**
2443
+ * A number attribute that is traditionally used for headings h1-h6.
2444
+ */
2445
+ level?: number;
2446
+
2447
+ /**
2448
+ * An accessible name for the element, such as a text in a button or a label for an input.
2449
+ */
2450
+ name?: string | RegExp;
2451
+
2452
+ /**
2453
+ * A boolean attribute that can be used to indicate if a checkbox is checked or not.
2454
+ */
2455
+ checked?: boolean;
2456
+
2457
+ /**
2458
+ * A boolean attribute that can be used to indicate if an element is disabled or not.
2459
+ */
2460
+ disabled?: boolean;
2461
+
2462
+ /**
2463
+ * A boolean attribute that can be used to indicate if an element is expanded or not.
2464
+ */
2465
+ expanded?: boolean;
2466
+
2467
+ /**
2468
+ * A boolean attribute that can be used to indicate if an element is pressed or not.
2469
+ */
2470
+ pressed?: boolean;
2471
+
2472
+ /**
2473
+ * A boolean attribute that can be used to indicate if an element is selected or not.
2474
+ */
2475
+ selected?: boolean;
2476
+ },
2477
+ ): Locator;
2478
+
2479
+ /**
2480
+ * Returns {@link Locator} to the element with the corresponding alt text.
2481
+ *
2482
+ * @example
2483
+ * ```js
2484
+ * const locator = frameLocator.getByAltText('pizza');
2485
+ *
2486
+ * await locator.click();
2487
+ * ```
2488
+ *
2489
+ * @param altText The alt text of the element.
2490
+ * @param options Options to use.
2491
+ * @returns The locator to the element with the corresponding alt text.
2492
+ */
2493
+ getByAltText(
2494
+ altText: string | RegExp,
2495
+ options?: {
2496
+ /**
2497
+ * Whether the locator should be exact.
2498
+ *
2499
+ * @defaultValue false
2500
+ */
2501
+ exact?: boolean;
2502
+ },
2503
+ ): Locator;
2504
+
2505
+ /**
2506
+ * Returns {@link Locator} to the element with the corresponding label text.
2507
+ *
2508
+ * @example
2509
+ * ```js
2510
+ * const locator = frameLocator.getByLabel('Password');
2511
+ *
2512
+ * await locator.fill('my-password');
2513
+ * ```
2514
+ *
2515
+ * @param label The label text of the element.
2516
+ * @param options Options to use.
2517
+ * @returns The locator to the element with the corresponding label text.
2518
+ */
2519
+ getByLabel(
2520
+ label: string | RegExp,
2521
+ options?: {
2522
+ /**
2523
+ * Whether the locator should be exact.
2524
+ *
2525
+ * @defaultValue false
2526
+ */
2527
+ exact?: boolean;
2528
+ },
2529
+ ): Locator;
2530
+
2531
+ /**
2532
+ * Allows locating elements by their text content. Returns {@link Locator}.
2533
+ *
2534
+ * Consider the following DOM structure:
2535
+ *
2536
+ * ```html
2537
+ * <div>Hello <span>world</span></div>
2538
+ * <div>Hello</div>
2539
+ * ```
2540
+ *
2541
+ * You can locate by text substring, exact string, or a regular expression:
2542
+ *
2543
+ * @example
2544
+ * ```js
2545
+ * // Matches <span>
2546
+ * frameLocator.getByText('world');
2547
+ *
2548
+ * // Matches first <div>
2549
+ * frameLocator.getByText('Hello world');
2550
+ *
2551
+ * // Matches second <div>
2552
+ * frameLocator.getByText('Hello', { exact: true });
2553
+ *
2554
+ * // Matches both <div>s
2555
+ * frameLocator.getByText(/Hello/);
2556
+ *
2557
+ * // Matches second <div>
2558
+ * frameLocator.getByText(/^hello$/i);
2559
+ * ```
2560
+ *
2561
+ * Matching by text always normalizes whitespace, even with exact match. For
2562
+ * example, it turns multiple spaces into one, turns line breaks into spaces
2563
+ * and ignores leading and trailing whitespace.
2564
+ *
2565
+ * Input elements of the type `button` and `submit` are matched by their
2566
+ * `value` instead of the text content. For example, locating by text
2567
+ * `"Log in"` matches `<input type=button value="Log in">`.
2568
+ *
2569
+ * @param text Text to locate the element by.
2570
+ * @param options Options to use.
2571
+ * @returns The locator to the element with the corresponding text content.
2572
+ */
2573
+ getByText(
2574
+ text: string | RegExp,
2575
+ options?: {
2576
+ /**
2577
+ * Whether to find an exact match: case-sensitive and whole-string.
2578
+ * Default to false. Ignored when locating by a regular expression.
2579
+ * Note that exact match still trims whitespace.
2580
+ *
2581
+ * @defaultValue false
2582
+ */
2583
+ exact?: boolean;
2584
+ },
2585
+ ): Locator;
2586
+
2587
+ /**
2588
+ * Returns {@link Locator} to the element with the corresponding test ID.
2589
+ * Note that this method only supports the `data-testid` attribute.
2590
+ *
2591
+ * @example
2592
+ * HTML:
2593
+ * ```html
2594
+ * <button data-testid="submit-button">Submit</button>
2595
+ * ```
2596
+ *
2597
+ * JavaScript:
2598
+ * ```js
2599
+ * const locator = frameLocator.getByTestId('submit-button');
2600
+ *
2601
+ * await locator.click();
2602
+ * ```
2603
+ *
2604
+ * @param testId The test ID of the element.
2605
+ * @returns The locator to the element with the corresponding test ID.
2606
+ */
2607
+ getByTestId(testId: string | RegExp): Locator;
2608
+
2609
+ /**
2610
+ * Returns {@link Locator} to the element with the corresponding placeholder text.
2611
+ *
2612
+ * @example
2613
+ * ```js
2614
+ * const locator = frameLocator.getByPlaceholder('name@example.com');
2615
+ *
2616
+ * await locator.fill('my.name@example.com');
2617
+ * ```
2618
+ *
2619
+ * @param placeholder The placeholder text of the element.
2620
+ * @param options Options to use.
2621
+ * @returns The locator to the element with the corresponding placeholder text.
2622
+ */
2623
+ getByPlaceholder(
2624
+ placeholder: string | RegExp,
2625
+ options?: {
2626
+ /**
2627
+ * Whether the locator should be exact.
2628
+ *
2629
+ * @defaultValue false
2630
+ */
2631
+ exact?: boolean;
2632
+ },
2633
+ ): Locator;
2634
+
2635
+ /**
2636
+ * Returns {@link Locator} to the element with the corresponding title text.
2637
+ *
2638
+ * @example
2639
+ * ```js
2640
+ * const locator = frameLocator.getByTitle('Information box');
2641
+ *
2642
+ * await locator.click();
2643
+ * ```
2644
+ *
2645
+ * @param title The title text of the element.
2646
+ * @param options Options to use.
2647
+ * @returns The locator to the element with the corresponding title text.
2648
+ */
2649
+ getByTitle(
2650
+ title: string | RegExp,
2651
+ options?: {
2652
+ /**
2653
+ * Whether the locator should be exact.
2654
+ *
2655
+ * @defaultValue false
2656
+ */
2657
+ exact?: boolean;
2658
+ },
2659
+ ): Locator;
2660
+ }
2661
+
2662
+ /**
2663
+ * JSHandle represents an in-page JavaScript object.
2664
+ */
2665
+ export interface JSHandle<T = any> {
2666
+ /**
2667
+ * Returns either `null` or the object handle itself, if the object handle is
2668
+ * an instance of `ElementHandle`.
2669
+ * @returns The ElementHandle if available.
2670
+ */
2671
+ asElement(): Promise<ElementHandle | null>;
2672
+
2673
+ /**
2674
+ * Stops referencing the element handle.
2675
+ */
2676
+ dispose(): Promise<void>;
2677
+
2678
+ /**
2679
+ * Evaluates the page function and returns its return value.
2680
+ * This method passes this handle as the first argument to the page function.
2681
+ * @param pageFunction The function to be evaluated.
2682
+ * @param args The arguments to pass to the page function.
2683
+ * @returns The return value of `pageFunction`.
2684
+ */
2685
+ evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg?: Arg): Promise<R>;
2686
+
2687
+ /**
2688
+ * Evaluates the page function and returns a `JSHandle`.
2689
+ * This method passes this handle as the first argument to the page function.
2690
+ * Unlike `evaluate`, `evaluateHandle` returns the value as a `JSHandle`
2691
+ * @param pageFunction The function to be evaluated.
2692
+ * @param args The arguments to pass to the page function.
2693
+ * @returns A JSHandle of the return value of `pageFunction`.
2694
+ */
2695
+ evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg?: Arg): Promise<JSHandle<R>>;
2696
+
2697
+ /**
2698
+ * Fetches a map with own property names of of the `JSHandle` with their values as
2699
+ * `JSHandle` instances.
2700
+ * @returns A map with property names as keys and `JSHandle` instances for the property values.
2701
+ */
2702
+ getProperties(): Promise<Map<string, JSHandle>>;
2703
+
2704
+ /**
2705
+ * Fetches a JSON representation of the object.
2706
+ * @returns A JSON representation of the object.
2707
+ */
2708
+ jsonValue(): Promise<any>;
2709
+ }
2710
+
2711
+ /**
2712
+ * Keyboard provides an API for managing a virtual keyboard.
2713
+ */
2714
+ export interface Keyboard {
2715
+ /**
2716
+ * Sends a key down message to a session target.
2717
+ * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
2718
+ * @param key Name of key to press, such as `ArrowLeft`.
2719
+ */
2720
+ down(key: string): Promise<void>;
2721
+
2722
+ /**
2723
+ * Dispatches an `input` event with the given `text`.
2724
+ * This method does not emit `keyDown`, `keyUp` or `keyPress` events.
2725
+ * @param text Event text.
2726
+ */
2727
+ insertText(text: string): Promise<void>;
2728
+
2729
+ /**
2730
+ * Sends a key press message to a session target.
2731
+ * A press message consists of successive key down and up messages.
2732
+ * @param key Sequence of keys to press.
2733
+ * @param options Specifies the typing options.
2734
+ */
2735
+ press(key: string, options?: { delay?: number }): Promise<void>;
2736
+
2737
+ /**
2738
+ * Type sends a `press` message to a session target for each character in text.
2739
+ * It sends an insertText message if a character is not among
2740
+ * valid characters in the keyboard's layout.
2741
+ * Modifier keys `Shift`, `Control`, `Alt`, `Meta` are _not_ respected.
2742
+ * @param text A text to type into a focused element.
2743
+ * @param options Specifies the typing options.
2744
+ */
2745
+ type(text: string, options?: { delay?: number }): Promise<void>;
2746
+
2747
+ /**
2748
+ * Sends a key up message to a session target.
2749
+ * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
2750
+ * @param key Name of key to release, such as `ArrowLeft`.
2751
+ */
2752
+ up(key: string): Promise<void>;
2753
+ }
2754
+
2755
+ export interface LocatorOptions {
2756
+ /**
2757
+ * Matches only elements that contain the specified text. String or regular expression.
2758
+ */
2759
+ hasText?: string | RegExp;
2760
+
2761
+ /**
2762
+ * Matches only elements that do not contain the specified text. String or regular expression.
2763
+ */
2764
+ hasNotText?: string | RegExp;
2765
+ }
2766
+
2767
+ export interface LocatorFilterOptions {
2768
+ /**
2769
+ * Matches only elements that contain the specified text. String or regular expression.
2770
+ */
2771
+ hasText?: string | RegExp;
2772
+
2773
+ /**
2774
+ * Matches only elements that do not contain the specified text. String or regular expression.
2775
+ */
2776
+ hasNotText?: string | RegExp;
2777
+ }
2778
+
2779
+ /**
2780
+ * The Locator API makes it easier to work with dynamically changing elements.
2781
+ * Some of the benefits of using it over existing ways to locate an element
2782
+ * (e.g. Page.$()) include:
2783
+ *
2784
+ * - Helps with writing robust tests by finding an element even if the
2785
+ * underlying frame navigates.
2786
+ * - Makes it easier to work with dynamic web pages and SPAs built with Svelte,
2787
+ * React, Vue, etc.
2788
+ */
2789
+ export interface Locator {
2790
+ /**
2791
+ * Returns an array of locators matching the selector.
2792
+ *
2793
+ * **Usage**
2794
+ *
2795
+ * ```js
2796
+ * // Select all options
2797
+ * for (const option of await page.locator('option').all())
2798
+ * await option.click();
2799
+ * ```
2800
+ *
2801
+ * @returns Array of locators
2802
+ */
2803
+ all(): Promise<Locator[]>;
2804
+
2805
+ /**
2806
+ * Returns the bounding box of the element that this locator points to.
2807
+ *
2808
+ * **Usage**
2809
+ *
2810
+ * ```js
2811
+ * const locator = page.locator('#my-element');
2812
+ * const boundingBox = await locator.boundingBox();
2813
+ * ```
2814
+ *
2815
+ * @param options Options to use.
2816
+ * @returns The bounding box of the element, or null if the element is not visible.
2817
+ */
2818
+ boundingBox(options?: TimeoutOptions): Promise<Rect | null>;
2819
+
2820
+ /**
2821
+ * Clears text boxes and input fields of any existing values.
2822
+ *
2823
+ * **Usage**
2824
+ *
2090
2825
  * ```js
2091
2826
  * // Clears the input field matching the selector.
2092
2827
  * page.locator('input[name="login"]').clear();
@@ -2094,248 +2829,628 @@ export interface Locator {
2094
2829
  *
2095
2830
  * @param options Options to use.
2096
2831
  */
2097
- clear(options?: ElementHandleOptions): Promise<void>;
2832
+ clear(options?: ElementHandleOptions): Promise<void>;
2833
+
2834
+ /**
2835
+ * Mouse click on the chosen element.
2836
+ * @param options Options to use.
2837
+ * @returns Promise which resolves when the element is successfully clicked.
2838
+ */
2839
+ click(options?: MouseMoveOptions & MouseMultiClickOptions): Promise<void>;
2840
+
2841
+ /**
2842
+ * Returns a `FrameLocator` that can be used to locate elements within an
2843
+ * `iframe`.
2844
+ * @returns A `FrameLocator`.
2845
+ */
2846
+ contentFrame(): FrameLocator;
2847
+
2848
+ /**
2849
+ * Returns the number of elements matching the selector.
2850
+ *
2851
+ * **Usage**
2852
+ *
2853
+ * ```js
2854
+ * const count = await page.locator('input').count();
2855
+ * ```
2856
+ *
2857
+ * @returns Promise which resolves with the number of elements matching the selector.
2858
+ */
2859
+ count(): Promise<number>;
2860
+
2861
+ /**
2862
+ * Mouse double click on the chosen element.
2863
+ * @param options Options to use.
2864
+ */
2865
+ dblclick(options?: MouseMoveOptions & MouseMultiClickOptions): Promise<void>;
2866
+
2867
+ /**
2868
+ * Use this method to select an `input type="checkbox"`.
2869
+ * @param options Options to use.
2870
+ */
2871
+ check(options?: ElementClickOptions): Promise<void>;
2872
+
2873
+ /**
2874
+ * Use this method to unselect an `input type="checkbox"`.
2875
+ * @param options Options to use.
2876
+ */
2877
+ uncheck(options?: ElementClickOptions): Promise<void>;
2878
+
2879
+ /**
2880
+ * Checks to see if the `input type="checkbox"` is selected or not.
2881
+ * @param options Options to use.
2882
+ * @returns `true` if the element is checked, `false` otherwise.
2883
+ */
2884
+ isChecked(options?: TimeoutOptions): Promise<boolean>;
2885
+
2886
+ /**
2887
+ * Checks if the element is editable.
2888
+ * @param options Options to use.
2889
+ * @returns `true` if the element is editable, `false` otherwise.
2890
+ */
2891
+ isEditable(options?: TimeoutOptions): Promise<boolean>;
2892
+
2893
+ /**
2894
+ * Checks if the element is `enabled`.
2895
+ * @param options Options to use.
2896
+ * @returns `true` if the element is enabled, `false` otherwise.
2897
+ */
2898
+ isEnabled(options?: TimeoutOptions): Promise<boolean>;
2899
+
2900
+ /**
2901
+ * Checks if the element is `disabled`.
2902
+ * @param options Options to use.
2903
+ * @returns `true` if the element is disabled, `false` otherwise.
2904
+ */
2905
+ isDisabled(options?: TimeoutOptions): Promise<boolean>;
2906
+
2907
+ /**
2908
+ * Checks if the element is `visible`.
2909
+ * @returns `true` if the element is visible, `false` otherwise.
2910
+ */
2911
+ isVisible(): Promise<boolean>;
2912
+
2913
+ /**
2914
+ * Checks if the element is `hidden`.
2915
+ * @returns `true` if the element is hidden, `false` otherwise.
2916
+ */
2917
+ isHidden(): Promise<boolean>;
2918
+
2919
+ /**
2920
+ * Fill an `input`, `textarea` or `contenteditable` element with the provided value.
2921
+ * @param value Value to fill for the `input` or `textarea` element.
2922
+ * @param options Options to use.
2923
+ */
2924
+ fill(value: string, options?: ElementHandleOptions): Promise<void>;
2925
+
2926
+ /**
2927
+ * Returns locator to the first matching element.
2928
+ *
2929
+ * **Usage**
2930
+ *
2931
+ * ```js
2932
+ * const firstRow = await page.locator('tr').first();
2933
+ * ```
2934
+ *
2935
+ * @returns Locator.
2936
+ */
2937
+ first(): Locator;
2938
+
2939
+ /**
2940
+ * Focuses the element using locator's selector.
2941
+ * @param options Options to use.
2942
+ */
2943
+ focus(options?: TimeoutOptions): Promise<void>;
2944
+
2945
+ /**
2946
+ * Returns the element attribute value for the given attribute name.
2947
+ * @param name Attribute name to retrieve value for.
2948
+ * @param options Options to use.
2949
+ * @returns Attribute value.
2950
+ */
2951
+ getAttribute(name: string, options?: TimeoutOptions): Promise<string | null>;
2952
+
2953
+ /**
2954
+ * Returns the `element.innerHTML`.
2955
+ * @param options Options to use.
2956
+ * @returns Element's innerHTML.
2957
+ */
2958
+ innerHTML(options?: TimeoutOptions): Promise<string>;
2959
+
2960
+ /**
2961
+ * Returns the `element.innerText`.
2962
+ * @param options Options to use.
2963
+ * @returns Element's innerText.
2964
+ */
2965
+ innerText(options?: TimeoutOptions): Promise<string>;
2966
+
2967
+ /**
2968
+ * Returns the `element.textContent`.
2969
+ * @param options Options to use.
2970
+ * @returns Element's textContent.
2971
+ */
2972
+ textContent(options?: TimeoutOptions): Promise<string | null>;
2973
+
2974
+ /**
2975
+ * Returns `input.value` for the selected `input`, `textarea` or `select` element.
2976
+ * @param options Options to use.
2977
+ * @returns The input value of the element.
2978
+ */
2979
+ inputValue(options?: TimeoutOptions): Promise<string>;
2980
+
2981
+ /**
2982
+ * Returns locator to the last matching element.
2983
+ *
2984
+ * **Usage**
2985
+ *
2986
+ * ```js
2987
+ * const lastRow = await page.locator('tr').last();
2988
+ * ```
2989
+ *
2990
+ * @returns Locator.
2991
+ */
2992
+ last(): Locator;
2098
2993
 
2099
2994
  /**
2100
- * Mouse click on the chosen element.
2101
- * @param options Options to use.
2102
- * @returns Promise which resolves when the element is successfully clicked.
2995
+ * The method finds all elements matching the selector and creates a new
2996
+ * locator that matches all of them. This method can be used to further
2997
+ * refine the locator by chaining additional selectors.
2998
+ *
2999
+ * @example
3000
+ * ```js
3001
+ * const rows = page.locator('table tr');
3002
+ * const cell = rows.locator('.selected');
3003
+ *
3004
+ * // Use with options to filter
3005
+ * const orangeButton = fruitsSection.locator('button', { hasText: 'Add to Cart' });
3006
+ * ```
3007
+ *
3008
+ * @param selector A selector to use when resolving DOM element.
3009
+ * @param options Options to use for filtering.
3010
+ * @returns The new locator.
2103
3011
  */
2104
- click(options?: MouseMoveOptions & MouseMultiClickOptions): Promise<void>;
3012
+ locator(selector: string, options?: LocatorOptions): Locator;
2105
3013
 
2106
3014
  /**
2107
- * Returns the number of elements matching the selector.
3015
+ * Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element.
2108
3016
  *
2109
3017
  * **Usage**
2110
3018
  *
2111
3019
  * ```js
2112
- * const count = await page.locator('input').count();
3020
+ * const secondRow = await page.locator('tr').nth(1);
2113
3021
  * ```
2114
3022
  *
2115
- * @returns Promise which resolves with the number of elements matching the selector.
3023
+ * @param index
3024
+ * @returns Locator
2116
3025
  */
2117
- count(): Promise<number>;
3026
+ nth(index: number): Locator;
2118
3027
 
2119
3028
  /**
2120
- * Mouse double click on the chosen element.
3029
+ * Select one or more options which match the values. If the select has the multiple attribute, all matching options are selected,
3030
+ * otherwise only the first option matching one of the passed options is selected.
3031
+ *
3032
+ * @example
3033
+ * ```js
3034
+ * // Single selection matching the value or label
3035
+ * locator.selectOption('blue');
3036
+ *
3037
+ * // single selection matching the label
3038
+ * locator.selectOption({ label: 'Blue' });
3039
+ *
3040
+ * // multiple selection
3041
+ * locator.selectOption(['red', 'green', 'blue']);
3042
+ * ```
3043
+ *
3044
+ * @param values Values of options to select.
2121
3045
  * @param options Options to use.
3046
+ * @returns List of selected options.
2122
3047
  */
2123
- dblclick(options?: MouseMoveOptions & MouseMultiClickOptions): Promise<void>;
3048
+ selectOption(
3049
+ values: string | string[] | { value?: string; label?: string; index?: number },
3050
+ options?: ElementHandleOptions,
3051
+ ): Promise<string[]>;
2124
3052
 
2125
3053
  /**
2126
- * Use this method to select an `input type="checkbox"`.
2127
- * @param options Options to use.
3054
+ * Checks or unchecks the input checkbox element.
3055
+ * @param checked Whether to check or uncheck the element.
3056
+ * @param options Options to customize the check action.
3057
+ * @returns A promise that resolves when the element is checked or unchecked.
2128
3058
  */
2129
- check(options?: ElementClickOptions): Promise<void>;
3059
+ setChecked(checked: boolean, options?: FrameCheckOptions): Promise<void>;
2130
3060
 
2131
3061
  /**
2132
- * Use this method to unselect an `input type="checkbox"`.
2133
- * @param options Options to use.
3062
+ * Press a single key on the keyboard or a combination of keys.
3063
+ * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
3064
+ * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
3065
+ * @param options Keyboard press options.
2134
3066
  */
2135
- uncheck(options?: ElementClickOptions): Promise<void>;
3067
+ press(key: string, options?: KeyboardPressOptions): Promise<void>;
2136
3068
 
2137
3069
  /**
2138
- * Checks to see if the `input type="checkbox"` is selected or not.
2139
- * @param options Options to use.
2140
- * @returns `true` if the element is checked, `false` otherwise.
3070
+ * Type a text into the input field.
3071
+ * @param text Text to type into the input field.
3072
+ * @param options Typing options.
2141
3073
  */
2142
- isChecked(options?: TimeoutOptions): Promise<boolean>;
3074
+ type(text: string, options?: KeyboardPressOptions): Promise<void>;
2143
3075
 
2144
3076
  /**
2145
- * Checks if the element is editable.
3077
+ * Hover over the element.
2146
3078
  * @param options Options to use.
2147
- * @returns `true` if the element is editable, `false` otherwise.
2148
3079
  */
2149
- isEditable(options?: TimeoutOptions): Promise<boolean>;
3080
+ hover(options?: MouseMoveOptions): Promise<void>;
2150
3081
 
2151
3082
  /**
2152
- * Checks if the element is `enabled`.
3083
+ * Tap on the chosen element.
2153
3084
  * @param options Options to use.
2154
- * @returns `true` if the element is enabled, `false` otherwise.
2155
3085
  */
2156
- isEnabled(options?: TimeoutOptions): Promise<boolean>;
3086
+ tap(options?: MouseMoveOptions): Promise<void>;
2157
3087
 
2158
3088
  /**
2159
- * Checks if the element is `disabled`.
3089
+ * Dispatches HTML DOM event types e.g. `click`.
3090
+ * @param type DOM event type.
3091
+ * @param eventInit Event-specific properties.
2160
3092
  * @param options Options to use.
2161
- * @returns `true` if the element is disabled, `false` otherwise.
2162
- */
2163
- isDisabled(options?: TimeoutOptions): Promise<boolean>;
2164
-
2165
- /**
2166
- * Checks if the element is `visible`.
2167
- * @returns `true` if the element is visible, `false` otherwise.
2168
- */
2169
- isVisible(): Promise<boolean>;
2170
-
2171
- /**
2172
- * Checks if the element is `hidden`.
2173
- * @returns `true` if the element is hidden, `false` otherwise.
2174
3093
  */
2175
- isHidden(): Promise<boolean>;
3094
+ dispatchEvent(type: string, eventInit?: EvaluationArgument, options?: TimeoutOptions): Promise<void>;
2176
3095
 
2177
3096
  /**
2178
- * Fill an `input`, `textarea` or `contenteditable` element with the provided value.
2179
- * @param value Value to fill for the `input` or `textarea` element.
2180
- * @param options Options to use.
3097
+ * Wait for the element to be in a particular state e.g. `visible`.
3098
+ * @param options Wait options.
2181
3099
  */
2182
- fill(value: string, options?: ElementHandleOptions): Promise<void>;
3100
+ waitFor(options?: { state?: ElementState } & TimeoutOptions): Promise<void>;
2183
3101
 
2184
3102
  /**
2185
- * Returns locator to the first matching element.
2186
- *
2187
- * **Usage**
3103
+ * Returns a new Locator that matches only elements with the given options.
2188
3104
  *
3105
+ * @example
2189
3106
  * ```js
2190
- * const firstRow = await page.locator('tr').first();
3107
+ * // Filter list items that contain "Product 2" text
3108
+ * const product2Item = page
3109
+ * .locator('li')
3110
+ * .filter({ hasText: 'Product 2' })
3111
+ * .first();
3112
+ *
3113
+ * // Filter list items that do NOT contain "Product 2" using regex
3114
+ * const product1Item = page
3115
+ * .locator('li')
3116
+ * .filter({ hasNotText: /Product 2/ })
3117
+ * .first();
2191
3118
  * ```
2192
3119
  *
2193
- * @returns Locator.
3120
+ * @param options Filter options.
3121
+ * @returns A new filtered Locator that can be chained with other methods.
2194
3122
  */
2195
- first(): Locator;
3123
+ filter(options: LocatorFilterOptions): Locator;
2196
3124
 
2197
3125
  /**
2198
- * Focuses the element using locator's selector.
3126
+ * Returns {@link Locator} to the element with the corresponding role.
3127
+ *
3128
+ * @example
3129
+ * ```js
3130
+ * const locator = locator.getByRole('button', { name: 'Pizza, Please!' });
3131
+ *
3132
+ * await locator.click();
3133
+ * ```
3134
+ *
3135
+ * @param role The role of the element.
2199
3136
  * @param options Options to use.
3137
+ * @returns The locator to the element with the corresponding role.
2200
3138
  */
2201
- focus(options?: TimeoutOptions): Promise<void>;
3139
+ getByRole(
3140
+ role:
3141
+ | "alert"
3142
+ | "alertdialog"
3143
+ | "application"
3144
+ | "article"
3145
+ | "banner"
3146
+ | "blockquote"
3147
+ | "button"
3148
+ | "caption"
3149
+ | "cell"
3150
+ | "checkbox"
3151
+ | "code"
3152
+ | "columnheader"
3153
+ | "combobox"
3154
+ | "complementary"
3155
+ | "contentinfo"
3156
+ | "definition"
3157
+ | "dialog"
3158
+ | "directory"
3159
+ | "document"
3160
+ | "emphasis"
3161
+ | "feed"
3162
+ | "figure"
3163
+ | "form"
3164
+ | "generic"
3165
+ | "grid"
3166
+ | "gridcell"
3167
+ | "group"
3168
+ | "heading"
3169
+ | "img"
3170
+ | "insertion"
3171
+ | "link"
3172
+ | "list"
3173
+ | "listbox"
3174
+ | "listitem"
3175
+ | "log"
3176
+ | "main"
3177
+ | "marquee"
3178
+ | "math"
3179
+ | "menu"
3180
+ | "menubar"
3181
+ | "menuitem"
3182
+ | "menuitemcheckbox"
3183
+ | "menuitemradio"
3184
+ | "meter"
3185
+ | "navigation"
3186
+ | "none"
3187
+ | "note"
3188
+ | "option"
3189
+ | "presentation"
3190
+ | "progressbar"
3191
+ | "radio"
3192
+ | "radiogroup"
3193
+ | "region"
3194
+ | "row"
3195
+ | "rowgroup"
3196
+ | "rowheader"
3197
+ | "scrollbar"
3198
+ | "search"
3199
+ | "searchbox"
3200
+ | "separator"
3201
+ | "slider"
3202
+ | "spinbutton"
3203
+ | "status"
3204
+ | "strong"
3205
+ | "subscript"
3206
+ | "superscript"
3207
+ | "switch"
3208
+ | "tab"
3209
+ | "table"
3210
+ | "tablist"
3211
+ | "tabpanel"
3212
+ | "term"
3213
+ | "textbox"
3214
+ | "time"
3215
+ | "timer"
3216
+ | "toolbar"
3217
+ | "tooltip"
3218
+ | "tree"
3219
+ | "treegrid"
3220
+ | "treeitem",
3221
+ options?: {
3222
+ /**
3223
+ * Whether the accessible `options.name` should be checked exactly for equality.
3224
+ *
3225
+ * @defaultValue false
3226
+ */
3227
+ exact?: boolean;
2202
3228
 
2203
- /**
2204
- * Returns the element attribute value for the given attribute name.
2205
- * @param name Attribute name to retrieve value for.
2206
- * @param options Options to use.
2207
- * @returns Attribute value.
2208
- */
2209
- getAttribute(name: string, options?: TimeoutOptions): Promise<string | null>;
3229
+ /**
3230
+ * Whether to include elements that are normally excluded from the accessibility tree.
3231
+ *
3232
+ * @defaultValue false
3233
+ */
3234
+ includeHidden?: boolean;
2210
3235
 
2211
- /**
2212
- * Returns the `element.innerHTML`.
2213
- * @param options Options to use.
2214
- * @returns Element's innerHTML.
2215
- */
2216
- innerHTML(options?: TimeoutOptions): Promise<string>;
3236
+ /**
3237
+ * A number attribute that is traditionally used for headings h1-h6.
3238
+ */
3239
+ level?: number;
3240
+
3241
+ /**
3242
+ * An accessible name for the element, such as a text in a button or a label for an input.
3243
+ */
3244
+ name?: string | RegExp;
3245
+
3246
+ /**
3247
+ * A boolean attribute that can be used to indicate if a checkbox is checked or not.
3248
+ */
3249
+ checked?: boolean;
3250
+
3251
+ /**
3252
+ * A boolean attribute that can be used to indicate if an element is disabled or not.
3253
+ */
3254
+ disabled?: boolean;
3255
+
3256
+ /**
3257
+ * A boolean attribute that can be used to indicate if an element is expanded or not.
3258
+ */
3259
+ expanded?: boolean;
2217
3260
 
2218
- /**
2219
- * Returns the `element.innerText`.
2220
- * @param options Options to use.
2221
- * @returns Element's innerText.
2222
- */
2223
- innerText(options?: TimeoutOptions): Promise<string>;
3261
+ /**
3262
+ * A boolean attribute that can be used to indicate if an element is pressed or not.
3263
+ */
3264
+ pressed?: boolean;
2224
3265
 
2225
- /**
2226
- * Returns the `element.textContent`.
2227
- * @param options Options to use.
2228
- * @returns Element's textContent.
2229
- */
2230
- textContent(options?: TimeoutOptions): Promise<string | null>;
3266
+ /**
3267
+ * A boolean attribute that can be used to indicate if an element is selected or not.
3268
+ */
3269
+ selected?: boolean;
3270
+ },
3271
+ ): Locator;
2231
3272
 
2232
3273
  /**
2233
- * Returns `input.value` for the selected `input`, `textarea` or `select` element.
3274
+ * Returns {@link Locator} to the element with the corresponding alt text.
3275
+ *
3276
+ * @example
3277
+ * ```js
3278
+ * const locator = locator.getByAltText('pizza');
3279
+ *
3280
+ * await locator.click();
3281
+ * ```
3282
+ *
3283
+ * @param altText The alt text of the element.
2234
3284
  * @param options Options to use.
2235
- * @returns The input value of the element.
3285
+ * @returns The locator to the element with the corresponding alt text.
2236
3286
  */
2237
- inputValue(options?: TimeoutOptions): Promise<string>;
3287
+ getByAltText(
3288
+ altText: string | RegExp,
3289
+ options?: {
3290
+ /**
3291
+ * Whether the locator should be exact.
3292
+ *
3293
+ * @defaultValue false
3294
+ */
3295
+ exact?: boolean;
3296
+ },
3297
+ ): Locator;
2238
3298
 
2239
3299
  /**
2240
- * Returns locator to the last matching element.
2241
- *
2242
- * **Usage**
3300
+ * Returns {@link Locator} to the element with the corresponding label text.
2243
3301
  *
3302
+ * @example
2244
3303
  * ```js
2245
- * const lastRow = await page.locator('tr').last();
3304
+ * const locator = locator.getByLabel('Password');
3305
+ *
3306
+ * await locator.fill('my-password');
2246
3307
  * ```
2247
3308
  *
2248
- * @returns Locator.
3309
+ * @param label The label text of the element.
3310
+ * @param options Options to use.
3311
+ * @returns The locator to the element with the corresponding label text.
2249
3312
  */
2250
- last(): Locator;
3313
+ getByLabel(
3314
+ label: string | RegExp,
3315
+ options?: {
3316
+ /**
3317
+ * Whether the locator should be exact.
3318
+ *
3319
+ * @defaultValue false
3320
+ */
3321
+ exact?: boolean;
3322
+ },
3323
+ ): Locator;
2251
3324
 
2252
3325
  /**
2253
- * Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element.
3326
+ * Allows locating elements by their text content. Returns {@link Locator}.
2254
3327
  *
2255
- * **Usage**
3328
+ * Consider the following DOM structure:
2256
3329
  *
2257
- * ```js
2258
- * const secondRow = await page.locator('tr').nth(1);
3330
+ * ```html
3331
+ * <div>Hello <span>world</span></div>
3332
+ * <div>Hello</div>
2259
3333
  * ```
2260
3334
  *
2261
- * @param index
2262
- * @returns Locator
2263
- */
2264
- nth(index: number): Locator;
2265
-
2266
- /**
2267
- * Select one or more options which match the values. If the select has the multiple attribute, all matching options are selected,
2268
- * otherwise only the first option matching one of the passed options is selected.
3335
+ * You can locate by text substring, exact string, or a regular expression:
2269
3336
  *
2270
3337
  * @example
2271
3338
  * ```js
2272
- * // Single selection matching the value or label
2273
- * locator.selectOption('blue');
3339
+ * // Matches <span>
3340
+ * locator.getByText('world');
2274
3341
  *
2275
- * // single selection matching the label
2276
- * locator.selectOption({ label: 'Blue' });
3342
+ * // Matches first <div>
3343
+ * locator.getByText('Hello world');
2277
3344
  *
2278
- * // multiple selection
2279
- * locator.selectOption(['red', 'green', 'blue']);
3345
+ * // Matches second <div>
3346
+ * locator.getByText('Hello', { exact: true });
3347
+ *
3348
+ * // Matches both <div>s
3349
+ * locator.getByText(/Hello/);
3350
+ *
3351
+ * // Matches second <div>
3352
+ * locator.getByText(/^hello$/i);
2280
3353
  * ```
2281
3354
  *
2282
- * @param values Values of options to select.
3355
+ * Matching by text always normalizes whitespace, even with exact match. For
3356
+ * example, it turns multiple spaces into one, turns line breaks into spaces
3357
+ * and ignores leading and trailing whitespace.
3358
+ *
3359
+ * Input elements of the type `button` and `submit` are matched by their
3360
+ * `value` instead of the text content. For example, locating by text
3361
+ * `"Log in"` matches `<input type=button value="Log in">`.
3362
+ *
3363
+ * @param text Text to locate the element by.
2283
3364
  * @param options Options to use.
2284
- * @returns List of selected options.
2285
- */
2286
- selectOption(
2287
- values: string | string[] | { value?: string; label?: string; index?: number },
2288
- options?: ElementHandleOptions,
2289
- ): Promise<string[]>;
2290
-
2291
- /**
2292
- * Checks or unchecks the input checkbox element.
2293
- * @param checked Whether to check or uncheck the element.
2294
- * @param options Options to customize the check action.
2295
- * @returns A promise that resolves when the element is checked or unchecked.
2296
- */
2297
- setChecked(checked: boolean, options?: FrameCheckOptions): Promise<void>;
2298
-
2299
- /**
2300
- * Press a single key on the keyboard or a combination of keys.
2301
- * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
2302
- * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
2303
- * @param options Keyboard press options.
2304
- */
2305
- press(key: string, options?: KeyboardPressOptions): Promise<void>;
2306
-
2307
- /**
2308
- * Type a text into the input field.
2309
- * @param text Text to type into the input field.
2310
- * @param options Typing options.
3365
+ * @returns The locator to the element with the corresponding text content.
2311
3366
  */
2312
- type(text: string, options?: KeyboardPressOptions): Promise<void>;
3367
+ getByText(
3368
+ text: string | RegExp,
3369
+ options?: {
3370
+ /**
3371
+ * Whether to find an exact match: case-sensitive and whole-string.
3372
+ * Default to false. Ignored when locating by a regular expression.
3373
+ * Note that exact match still trims whitespace.
3374
+ *
3375
+ * @defaultValue false
3376
+ */
3377
+ exact?: boolean;
3378
+ },
3379
+ ): Locator;
2313
3380
 
2314
3381
  /**
2315
- * Hover over the element.
2316
- * @param options Options to use.
3382
+ * Returns {@link Locator} to the element with the corresponding test ID.
3383
+ * Note that this method only supports the `data-testid` attribute.
3384
+ *
3385
+ * @example
3386
+ * HTML:
3387
+ * ```html
3388
+ * <button data-testid="submit-button">Submit</button>
3389
+ * ```
3390
+ *
3391
+ * JavaScript:
3392
+ * ```js
3393
+ * const locator = locator.getByTestId('submit-button');
3394
+ *
3395
+ * await locator.click();
3396
+ * ```
3397
+ *
3398
+ * @param testId The test ID of the element.
3399
+ * @returns The locator to the element with the corresponding test ID.
2317
3400
  */
2318
- hover(options?: MouseMoveOptions): Promise<void>;
3401
+ getByTestId(testId: string | RegExp): Locator;
2319
3402
 
2320
3403
  /**
2321
- * Tap on the chosen element.
3404
+ * Returns {@link Locator} to the element with the corresponding placeholder text.
3405
+ *
3406
+ * @example
3407
+ * ```js
3408
+ * const locator = locator.getByPlaceholder('name@example.com');
3409
+ *
3410
+ * await locator.fill('my.name@example.com');
3411
+ * ```
3412
+ *
3413
+ * @param placeholder The placeholder text of the element.
2322
3414
  * @param options Options to use.
3415
+ * @returns The locator to the element with the corresponding placeholder text.
2323
3416
  */
2324
- tap(options?: MouseMoveOptions): Promise<void>;
3417
+ getByPlaceholder(
3418
+ placeholder: string | RegExp,
3419
+ options?: {
3420
+ /**
3421
+ * Whether the locator should be exact.
3422
+ *
3423
+ * @defaultValue false
3424
+ */
3425
+ exact?: boolean;
3426
+ },
3427
+ ): Locator;
2325
3428
 
2326
3429
  /**
2327
- * Dispatches HTML DOM event types e.g. `click`.
2328
- * @param type DOM event type.
2329
- * @param eventInit Event-specific properties.
3430
+ * Returns {@link Locator} to the element with the corresponding title text.
3431
+ *
3432
+ * @example
3433
+ * ```js
3434
+ * const locator = locator.getByTitle('Information box');
3435
+ *
3436
+ * await locator.click();
3437
+ * ```
3438
+ *
3439
+ * @param title The title text of the element.
2330
3440
  * @param options Options to use.
3441
+ * @returns The locator to the element with the corresponding title text.
2331
3442
  */
2332
- dispatchEvent(type: string, eventInit?: EvaluationArgument, options?: TimeoutOptions): Promise<void>;
2333
-
2334
- /**
2335
- * Wait for the element to be in a particular state e.g. `visible`.
2336
- * @param options Wait options.
2337
- */
2338
- waitFor(options?: { state?: ElementState } & TimeoutOptions): Promise<void>;
3443
+ getByTitle(
3444
+ title: string | RegExp,
3445
+ options?: {
3446
+ /**
3447
+ * Whether the locator should be exact.
3448
+ *
3449
+ * @defaultValue false
3450
+ */
3451
+ exact?: boolean;
3452
+ },
3453
+ ): Locator;
2339
3454
  }
2340
3455
 
2341
3456
  /**
@@ -3487,9 +4602,18 @@ export interface Page {
3487
4602
  * when the action takes place, which means locators can span over navigations
3488
4603
  * where the underlying dom changes.
3489
4604
  *
4605
+ * @example
4606
+ * ```js
4607
+ * const textbox = page.locator('#text1');
4608
+ *
4609
+ * // Create a locator with text filtering options
4610
+ * const submitButton = page.locator('button', { hasText: 'Pizza, Please!' });
4611
+ * ```
4612
+ *
3490
4613
  * @param selector A selector to use when resolving DOM element.
4614
+ * @param options Options to use for filtering.
3491
4615
  */
3492
- locator(selector: string): Locator;
4616
+ locator(selector: string, options?: LocatorOptions): Locator;
3493
4617
 
3494
4618
  /**
3495
4619
  * The page's main frame. Page is made up of frames in a hierarchical. At the
@@ -4334,6 +5458,36 @@ export interface Page {
4334
5458
  },
4335
5459
  ): Promise<void>;
4336
5460
 
5461
+ /**
5462
+ * Waits for the page to match against the URL for a Response object
5463
+ *
5464
+ * @example
5465
+ * ```js
5466
+ * const responsePromise = page.waitForResponse('https://example.com/resource');
5467
+ * await page.goto('https://example.com/resource');
5468
+ * const response = await responsePromise;
5469
+ * ```
5470
+ *
5471
+ * @param response Request URL string or regex to match against Response object.
5472
+ * @param options Options to use.
5473
+ */
5474
+ waitForResponse(
5475
+ response: string | RegExp,
5476
+ options?: {
5477
+ /**
5478
+ * Maximum operation time in milliseconds. Defaults to `30` seconds.
5479
+ * The default value can be changed via the
5480
+ * browserContext.setDefaultNavigationTimeout(timeout),
5481
+ * browserContext.setDefaultTimeout(timeout),
5482
+ * page.setDefaultNavigationTimeout(timeout) or
5483
+ * page.setDefaultTimeout(timeout) methods.
5484
+ *
5485
+ * Setting the value to `0` will disable the timeout.
5486
+ */
5487
+ timeout?: number;
5488
+ },
5489
+ ): Promise<Response | null>;
5490
+
4337
5491
  /**
4338
5492
  * **NOTE** Use web assertions that assert visibility or a locator-based
4339
5493
  * locator.waitFor([options]) instead.