chore: withdraw locator.enumerate (#19484)
This commit is contained in:
parent
7bc184f526
commit
3afd83c8cc
|
@ -458,36 +458,6 @@ Resolves given locator to the first matching DOM element. If no elements matchin
|
|||
|
||||
Resolves given locator to all matching DOM elements.
|
||||
|
||||
## async method: Locator.enumerate
|
||||
* since: v1.14
|
||||
* langs: js, python, csharp
|
||||
- returns: <[Array]<[Tuple]<[Locator],[int]>>>
|
||||
|
||||
When locator points to a list of elements, returns array of (locator, index) pairs,
|
||||
pointing to respective elements.
|
||||
|
||||
**Usage**
|
||||
|
||||
```js
|
||||
for (const [li, i] of await page.getByRole('listitem').enumerate())
|
||||
await li.click();
|
||||
```
|
||||
|
||||
```python async
|
||||
for (li, index) in await page.get_by_role('listitem').enumerate():
|
||||
await li.click();
|
||||
```
|
||||
|
||||
```python sync
|
||||
for (li, index) in page.get_by_role('listitem').enumerate():
|
||||
li.click();
|
||||
```
|
||||
|
||||
```csharp
|
||||
foreach (var (li, index) in await page.GetByRole('listitem').AllAsync())
|
||||
await li.ClickAsync();
|
||||
```
|
||||
|
||||
## async method: Locator.evaluate
|
||||
* since: v1.14
|
||||
- returns: <[Serializable]>
|
||||
|
|
|
@ -1389,28 +1389,6 @@ foreach (var row in await page.GetByRole(AriaRole.Listitem).AllAsync())
|
|||
Console.WriteLine(await row.TextContentAsync());
|
||||
```
|
||||
|
||||
Iterate elements with their respective indexes:
|
||||
|
||||
```js
|
||||
for (const [row, index] of await page.getByRole('listitem').enumerate())
|
||||
console.log(index, await row.textContent());
|
||||
```
|
||||
|
||||
```python async
|
||||
for (row, index) in await page.get_by_role('listitem').enumerate():
|
||||
print(index, await row.text_content())
|
||||
```
|
||||
|
||||
```python sync
|
||||
for (row, index) in page.get_by_role('listitem').enumerate():
|
||||
print(index, row.text_content())
|
||||
```
|
||||
|
||||
```csharp
|
||||
foreach (var (row, index) in await page.GetByRole('listitem').AllAsync())
|
||||
Console.WriteLine(index + ' ' + await row.TextContentAsync());
|
||||
```
|
||||
|
||||
Iterate using regular for loop:
|
||||
|
||||
```js
|
||||
|
|
|
@ -296,10 +296,6 @@ export class Locator implements api.Locator {
|
|||
return new Array(await this.count()).fill(0).map((e, i) => this.nth(i));
|
||||
}
|
||||
|
||||
async enumerate(): Promise<[Locator, number][]> {
|
||||
return new Array(await this.count()).fill(0).map((e, i) => [this.nth(i), i]);
|
||||
}
|
||||
|
||||
async allInnerTexts(): Promise<string[]> {
|
||||
return this._frame.$$eval(this._selector, ee => ee.map(e => (e as HTMLElement).innerText));
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import { ReadStream } from 'fs';
|
|||
import { Protocol } from './protocol';
|
||||
import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from './structs';
|
||||
|
||||
type Tuple<A,B> = [A,B];
|
||||
|
||||
type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
|
||||
state?: 'visible'|'attached';
|
||||
};
|
||||
|
@ -10254,20 +10252,6 @@ export interface Locator {
|
|||
*/
|
||||
elementHandles(): Promise<Array<ElementHandle>>;
|
||||
|
||||
/**
|
||||
* When locator points to a list of elements, returns array of (locator, index) pairs, pointing to respective
|
||||
* elements.
|
||||
*
|
||||
* **Usage**
|
||||
*
|
||||
* ```js
|
||||
* for (const [li, i] of await page.getByRole('listitem').enumerate())
|
||||
* await li.click();
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
enumerate(): Promise<Array<Tuple<Locator, number>>>;
|
||||
|
||||
/**
|
||||
* Returns the return value of `pageFunction` as a [JSHandle].
|
||||
*
|
||||
|
|
|
@ -23,13 +23,3 @@ it('locator.all should work', async ({ page }) => {
|
|||
texts.push(await p.textContent());
|
||||
expect(texts).toEqual(['A', 'B', 'C']);
|
||||
});
|
||||
|
||||
it('locator.enumerate should work', async ({ page }) => {
|
||||
await page.setContent(`<div><p>0</p><p>1</p><p>2</p><p>3</p></div>`);
|
||||
let items = 0;
|
||||
for (const [p, i] of await page.locator('div >> p').enumerate()) {
|
||||
++items;
|
||||
expect(await p.textContent()).toBe(String(i));
|
||||
}
|
||||
expect(items).toBe(4);
|
||||
});
|
||||
|
|
|
@ -20,8 +20,6 @@ import { ReadStream } from 'fs';
|
|||
import { Protocol } from './protocol';
|
||||
import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from './structs';
|
||||
|
||||
type Tuple<A,B> = [A,B];
|
||||
|
||||
type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
|
||||
state?: 'visible'|'attached';
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue