Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update queryAll example #1763

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ description: 'Browser module: page.$$(selector) method'

{{< admonition type="warning" >}}

Use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.
When possible, use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.

However, using `locator`s may not always work when selecting an element from a list or table, especially if there isn't a reliable way to consistently identify a single element (for example, due to changing or non-unique attributes). In such cases, `$$` remains useful.

{{< /admonition >}}

The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. This is particularly useful when you want to retrieve a list of elements, and iterate through them to find the one that you need for your test case.

### Returns

| Type | Description |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type | Description |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Promise<ElementHandle[]>` | A Promise that fulfills with the [ElementHandle](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/elementhandle/) array of the selector when matching elements are found. |

### Example
Expand All @@ -43,9 +45,21 @@ export const options = {
export default async function () {
const page = await browser.newPage();

await page.goto('https://test.k6.io/browser.php');
const text = await page.$$('#text1')[0];
await text.type('hello world');
await page.goto('https://test.k6.io/');

// Retrieve all the td elements.
const cells = await page.$$('td');
for (let i = 0; i < cells.length; i++) {
if ((await cells[i].innerText()) == '/pi.php?decimals=3') {
// When the element is found, click on it and
// wait for the navigation.
await Promise.all([page.waitForNavigation(), cells[i].click()]);
break;
}
}

// Wait for an important element to load.
await page.locator('//pre[text()="3.141"]').waitFor();
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ description: 'Browser module: page.$$(selector) method'

{{< admonition type="warning" >}}

Use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.
When possible, use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.

However, using `locator`s may not always work when selecting an element from a list or table, especially if there isn't a reliable way to consistently identify a single element (for example, due to changing or non-unique attributes). In such cases, `$$` remains useful.

{{< /admonition >}}

The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. This is particularly useful when you want to retrieve a list of elements, and iterate through them to find the one that you need for your test case.

### Returns

| Type | Description |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type | Description |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Promise<ElementHandle[]>` | A Promise that fulfills with the [ElementHandle](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/elementhandle/) array of the selector when matching elements are found. |

### Example
Expand All @@ -43,9 +45,21 @@ export const options = {
export default async function () {
const page = await browser.newPage();

await page.goto('https://test.k6.io/browser.php');
const text = await page.$$('#text1')[0];
await text.type('hello world');
await page.goto('https://test.k6.io/');

// Retrieve all the td elements.
const cells = await page.$$('td');
for (let i = 0; i < cells.length; i++) {
if ((await cells[i].innerText()) == '/pi.php?decimals=3') {
// When the element is found, click on it and
// wait for the navigation.
await Promise.all([page.waitForNavigation(), cells[i].click()]);
break;
}
}

// Wait for an important element to load.
await page.locator('//pre[text()="3.141"]').waitFor();
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ description: 'Browser module: page.$$(selector) method'

{{< admonition type="warning" >}}

Use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.
When possible, use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.

However, using `locator`s may not always work when selecting an element from a list or table, especially if there isn't a reliable way to consistently identify a single element (for example, due to changing or non-unique attributes). In such cases, `$$` remains useful.

{{< /admonition >}}

The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. This is particularly useful when you want to retrieve a list of elements, and iterate through them to find the one that you need for your test case.

### Returns

Expand Down Expand Up @@ -43,9 +45,21 @@ export const options = {
export default async function () {
const page = await browser.newPage();

await page.goto('https://test.k6.io/browser.php');
const text = await page.$$('#text1')[0];
await text.type('hello world');
await page.goto('https://test.k6.io/');

// Retrieve all the td elements.
const cells = await page.$$('td');
for (let i = 0; i < cells.length; i++) {
if ((await cells[i].innerText()) == '/pi.php?decimals=3') {
// When the element is found, click on it and
// wait for the navigation.
await Promise.all([page.waitForNavigation(), cells[i].click()]);
break;
}
}

// Wait for an important element to load.
await page.locator('//pre[text()="3.141"]').waitFor();
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ description: 'Browser module: page.$$(selector) method'

{{< admonition type="warning" >}}

Use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.
When possible, use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.

However, using `locator`s may not always work when selecting an element from a list or table, especially if there isn't a reliable way to consistently identify a single element (for example, due to changing or non-unique attributes). In such cases, `$$` remains useful.

{{< /admonition >}}

The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. This is particularly useful when you want to retrieve a list of elements, and iterate through them to find the one that you need for your test case.

### Returns

Expand Down Expand Up @@ -43,9 +45,21 @@ export const options = {
export default async function () {
const page = await browser.newPage();

await page.goto('https://test.k6.io/browser.php');
const text = await page.$$('#text1')[0];
await text.type('hello world');
await page.goto('https://test.k6.io/');

// Retrieve all the td elements.
const cells = await page.$$('td');
for (let i = 0; i < cells.length; i++) {
if ((await cells[i].innerText()) == '/pi.php?decimals=3') {
// When the element is found, click on it and
// wait for the navigation.
await Promise.all([page.waitForNavigation(), cells[i].click()]);
break;
}
}

// Wait for an important element to load.
await page.locator('//pre[text()="3.141"]').waitFor();
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ description: 'Browser module: page.$$(selector) method'

{{< admonition type="warning" >}}

Use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.
When possible, use locator-based [`page.locator(selector)`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/locator/) instead.

However, using `locator`s may not always work when selecting an element from a list or table, especially if there isn't a reliable way to consistently identify a single element (for example, due to changing or non-unique attributes). In such cases, `$$` remains useful.

{{< /admonition >}}

The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. This is particularly useful when you want to retrieve a list of elements, and iterate through them to find the one that you need for your test case.

### Returns

| Type | Description |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type | Description |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Promise<ElementHandle[]>` | A Promise that fulfills with the [ElementHandle](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/elementhandle/) array of the selector when matching elements are found. |

### Example
Expand All @@ -43,9 +45,21 @@ export const options = {
export default async function () {
const page = await browser.newPage();

await page.goto('https://test.k6.io/browser.php');
const text = await page.$$('#text1')[0];
await text.type('hello world');
await page.goto('https://test.k6.io/');

// Retrieve all the td elements.
const cells = await page.$$('td');
for (let i = 0; i < cells.length; i++) {
if ((await cells[i].innerText()) == '/pi.php?decimals=3') {
// When the element is found, click on it and
// wait for the navigation.
await Promise.all([page.waitForNavigation(), cells[i].click()]);
break;
}
}

// Wait for an important element to load.
await page.locator('//pre[text()="3.141"]').waitFor();
}
```

Expand Down
Loading