Skip to content

Commit 5fd04e5

Browse files
committed
Update locator.clear example
The existing example might have confused readers since an empty input element was being cleared. The change now brings in an example where an input field is filled in and then cleared.
1 parent dc877cc commit 5fd04e5

File tree

1 file changed

+20
-4
lines changed
  • docs/sources/next/javascript-api/k6-experimental/browser/locator

1 file changed

+20
-4
lines changed

docs/sources/next/javascript-api/k6-experimental/browser/locator/clear.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ Clears text boxes and input fields (`input`, `textarea` or `contenteditable` ele
2323
{{< code >}}
2424

2525
```javascript
26+
import { check } from 'k6';
2627
import { browser } from 'k6/experimental/browser';
2728

2829
export const options = {
2930
scenarios: {
30-
browser: {
31+
ui: {
3132
executor: 'shared-iterations',
3233
options: {
3334
browser: {
@@ -39,11 +40,26 @@ export const options = {
3940
};
4041

4142
export default async function () {
42-
const page = browser.newPage();
43+
const context = browser.newContext();
44+
const page = context.newPage();
4345

44-
await page.goto('https://test.k6.io/browser.php');
46+
await page.goto('https://test.k6.io/my_messages.php', { waitUntil: 'networkidle' });
4547

46-
page.locator('#text1').clear();
48+
// Fill an input element with some text that we will later clear.
49+
page.locator('input[name="login"]').type('admin');
50+
51+
// This checks that the element has been filled with text.
52+
check(page, {
53+
not_empty: (p) => p.locator('input[name="login"]').inputValue() != '',
54+
});
55+
56+
// Now clear the text from the element.
57+
page.locator('input[name="login"]').clear();
58+
59+
// This checks that the element is now empty.
60+
check(page, {
61+
empty: (p) => p.locator('input[name="login"]').inputValue() == '',
62+
});
4763

4864
page.close();
4965
}

0 commit comments

Comments
 (0)