@testdriverai/agent 7.11.229-canary → 7.11.231-test
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.
- package/docs/_data/examples-manifest.json +16 -16
- package/docs/_scripts/generate-examples.js +38 -45
- package/docs/agent.mdx +174 -93
- package/docs/assert.mdx +73 -269
- package/docs/aws-setup.mdx +196 -314
- package/docs/bring-your-own-machine.mdx +139 -206
- package/docs/cache.mdx +144 -151
- package/docs/caching.mdx +99 -89
- package/docs/captcha.mdx +126 -111
- package/docs/ci-cd.mdx +154 -543
- package/docs/click.mdx +74 -229
- package/docs/client.mdx +177 -231
- package/docs/copilot/auto-healing.mdx +86 -370
- package/docs/copilot/running-tests.mdx +121 -930
- package/docs/customizing-devices.mdx +74 -251
- package/docs/dashcam.mdx +72 -405
- package/docs/debugging-with-screenshots.mdx +105 -371
- package/docs/docs.json +75 -18
- package/docs/double-click.mdx +48 -68
- package/docs/errors.mdx +102 -176
- package/docs/events.mdx +170 -327
- package/docs/examples/{hover-text-with-description.mdx → add-to-cart.mdx} +30 -35
- package/docs/examples/assert.mdx +28 -41
- package/docs/examples/click-button.mdx +71 -0
- package/docs/examples/{hover-image.mdx → click-icon.mdx} +32 -28
- package/docs/examples/element-not-found.mdx +27 -26
- package/docs/examples/findall-coffee-icons.mdx +28 -32
- package/docs/examples/installer.mdx +61 -25
- package/docs/examples/launch-vscode-linux.mdx +28 -51
- package/docs/examples/navigate-and-scroll.mdx +82 -0
- package/docs/examples/parse.mdx +24 -28
- package/docs/examples/press-keys.mdx +28 -25
- package/docs/examples/scroll.mdx +25 -27
- package/docs/examples/type.mdx +26 -21
- package/docs/exec.mdx +92 -256
- package/docs/extract.mdx +69 -170
- package/docs/find.mdx +140 -736
- package/docs/focus-application.mdx +69 -246
- package/docs/generating-tests.mdx +103 -137
- package/docs/guide/best-practices-polling.mdx +65 -141
- package/docs/hosted.mdx +80 -144
- package/docs/hover.mdx +62 -235
- package/docs/locating-elements.mdx +74 -369
- package/docs/making-assertions.mdx +116 -74
- package/docs/mcp-setup.mdx +80 -63
- package/docs/mouse-down.mdx +48 -125
- package/docs/mouse-up.mdx +47 -129
- package/docs/options.mdx +75 -48
- package/docs/parse.mdx +95 -184
- package/docs/performing-actions.mdx +104 -94
- package/docs/press-keys.mdx +59 -299
- package/docs/provision.mdx +137 -182
- package/docs/quickstart-claude.mdx +85 -0
- package/docs/quickstart-github.mdx +62 -32
- package/docs/quickstart-manual.mdx +60 -33
- package/docs/quickstart-vscode.mdx +97 -0
- package/docs/quickstart.mdx +25 -9
- package/docs/redraw.mdx +101 -165
- package/docs/reusable-code.mdx +97 -200
- package/docs/right-click.mdx +47 -89
- package/docs/screenshot.mdx +47 -201
- package/docs/screenshots.mdx +87 -137
- package/docs/scroll.mdx +71 -154
- package/docs/secrets.mdx +96 -91
- package/docs/self-hosted.mdx +83 -142
- package/docs/snippets/enterprise.mdx +15 -0
- package/docs/styles.css +68 -0
- package/docs/test-results-json.mdx +167 -204
- package/docs/type.mdx +56 -304
- package/docs/variables.mdx +121 -81
- package/docs/wait.mdx +33 -31
- package/docs/what-is-testdriver.mdx +80 -32
- package/examples/{hover-text-with-description.test.mjs → add-to-cart.test.mjs} +4 -5
- package/examples/assert.test.mjs +3 -20
- package/examples/{hover-text.test.mjs → click-button.test.mjs} +3 -4
- package/examples/{hover-image.test.mjs → click-icon.test.mjs} +5 -6
- package/examples/element-not-found.test.mjs +3 -5
- package/examples/findall-coffee-icons.test.mjs +3 -3
- package/examples/installer.test.mjs +1 -1
- package/examples/launch-vscode-linux.test.mjs +6 -33
- package/examples/{scroll-keyboard.test.mjs → navigate-and-scroll.test.mjs} +4 -5
- package/examples/parse.test.mjs +1 -2
- package/examples/press-keys.test.mjs +4 -4
- package/examples/scroll.test.mjs +3 -6
- package/examples/type.test.mjs +5 -2
- package/lib/provision.js +6 -2
- package/package.json +1 -1
- package/sdk.d.ts +4 -2
- package/sdk.js +1 -1
- package/docs/claude-mcp-plugin.mdx +0 -244
- package/docs/elements.mdx +0 -606
- package/docs/examples/ai.mdx +0 -78
- package/docs/examples/captcha-api.mdx +0 -92
- package/docs/examples/chrome-extension.mdx +0 -156
- package/docs/examples/drag-and-drop.mdx +0 -100
- package/docs/examples/formatted-logging.mdx +0 -74
- package/docs/examples/hover-text.mdx +0 -70
- package/docs/examples/match-image.mdx +0 -97
- package/docs/examples/scroll-keyboard.mdx +0 -80
- package/docs/examples/scroll-until-text.mdx +0 -109
package/docs/click.mdx
CHANGED
|
@@ -1,287 +1,132 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "click()"
|
|
3
3
|
sidebarTitle: "click"
|
|
4
|
-
description: "Click
|
|
4
|
+
description: "Click an element you found, or click a point on the screen."
|
|
5
5
|
icon: "mouse-pointer"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
When you call this on an Element object, it clicks on the found element.
|
|
11
|
-
|
|
12
|
-
### Syntax
|
|
8
|
+
Click an element you've located with [`find()`](/find):
|
|
13
9
|
|
|
14
10
|
```javascript
|
|
15
|
-
await
|
|
11
|
+
const signInButton = await testdriver.find('Sign in button');
|
|
12
|
+
await signInButton.click();
|
|
16
13
|
```
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<ParamField path="action" type="string" default="click">
|
|
21
|
-
Type of click action: `'click'`, `'double-click'`, `'right-click'`, `'hover'`, `'mouseDown'`, `'mouseUp'`
|
|
22
|
-
</ParamField>
|
|
23
|
-
|
|
24
|
-
### Returns
|
|
25
|
-
|
|
26
|
-
`Promise<void>`
|
|
27
|
-
|
|
28
|
-
### Examples
|
|
15
|
+
Or chain it straight onto `find()`:
|
|
29
16
|
|
|
30
17
|
```javascript
|
|
31
|
-
|
|
32
|
-
const button = await testdriver.find('submit button');
|
|
33
|
-
await button.click();
|
|
34
|
-
|
|
35
|
-
// Double-click
|
|
36
|
-
const file = await testdriver.find('README.txt file');
|
|
37
|
-
await file.click('double-click');
|
|
38
|
-
|
|
39
|
-
// Right-click
|
|
40
|
-
const item = await testdriver.find('menu item');
|
|
41
|
-
await item.click('right-click');
|
|
42
|
-
|
|
43
|
-
// Hover (same as element.hover())
|
|
44
|
-
const tooltip = await testdriver.find('info icon');
|
|
45
|
-
await button.click('hover');
|
|
18
|
+
await testdriver.find('Sign in button').click();
|
|
46
19
|
```
|
|
47
20
|
|
|
48
|
-
##
|
|
21
|
+
## element.click(action)
|
|
49
22
|
|
|
50
|
-
|
|
23
|
+
Clicks the element at the point where `find()` located it.
|
|
51
24
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
await testdriver.click(x, y, action)
|
|
25
|
+
```typescript
|
|
26
|
+
element.click(action?: ClickAction): Promise<void>
|
|
56
27
|
```
|
|
57
28
|
|
|
58
29
|
### Parameters
|
|
59
30
|
|
|
60
|
-
<ParamField path="
|
|
61
|
-
|
|
62
|
-
</ParamField>
|
|
63
|
-
|
|
64
|
-
<ParamField path="y" type="number" required>
|
|
65
|
-
Y coordinate
|
|
66
|
-
</ParamField>
|
|
31
|
+
<ParamField path="action" type="ClickAction" default="click">
|
|
32
|
+
The mouse action to perform:
|
|
67
33
|
|
|
68
|
-
|
|
69
|
-
|
|
34
|
+
- `'click'`: a left click
|
|
35
|
+
- `'double-click'`: a double click, same as [`doubleClick()`](/double-click)
|
|
36
|
+
- `'right-click'`: a right click, same as [`rightClick()`](/right-click)
|
|
37
|
+
- `'hover'`: move the mouse there without clicking, same as [`hover()`](/hover)
|
|
38
|
+
- `'mouseDown'` and `'mouseUp'`: press or release the button, for dragging. See [mouseDown()](/mouse-down).
|
|
70
39
|
</ParamField>
|
|
71
40
|
|
|
72
|
-
###
|
|
73
|
-
|
|
74
|
-
`Promise<void>`
|
|
41
|
+
### Errors
|
|
75
42
|
|
|
76
|
-
|
|
43
|
+
Throws an `ElementNotFoundError` if `find()` didn't locate the element. Check `found()` first when the element might not be there:
|
|
77
44
|
|
|
78
45
|
```javascript
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
await testdriver.click(500, 300, 'double-click');
|
|
84
|
-
|
|
85
|
-
// Right-click at coordinates
|
|
86
|
-
await testdriver.click(500, 300, 'right-click');
|
|
46
|
+
const banner = await testdriver.find('cookie consent banner', { timeout: 0 });
|
|
47
|
+
if (banner.found()) {
|
|
48
|
+
await testdriver.find('Accept all cookies button').click();
|
|
49
|
+
}
|
|
87
50
|
```
|
|
88
51
|
|
|
89
|
-
##
|
|
52
|
+
## testdriver.click(options)
|
|
90
53
|
|
|
91
|
-
|
|
54
|
+
Clicks a point on the screen by its coordinates. Prefer `element.click()`, which keeps working when the layout or screen size changes.
|
|
92
55
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
```javascript
|
|
96
|
-
const button = await testdriver.find('Login button');
|
|
97
|
-
await button.click();
|
|
56
|
+
```typescript
|
|
57
|
+
testdriver.click(options: { x: number; y: number; action?: ClickAction }): Promise<void>
|
|
98
58
|
```
|
|
99
59
|
|
|
100
|
-
###
|
|
60
|
+
### Parameters
|
|
101
61
|
|
|
102
|
-
|
|
62
|
+
<ParamField path="options" type="object" required>
|
|
63
|
+
<Expandable title="properties">
|
|
64
|
+
<ParamField path="x" type="number" required>
|
|
65
|
+
Distance from the left edge of the screen, in pixels.
|
|
66
|
+
</ParamField>
|
|
67
|
+
<ParamField path="y" type="number" required>
|
|
68
|
+
Distance from the top edge of the screen, in pixels.
|
|
69
|
+
</ParamField>
|
|
70
|
+
<ParamField path="action" type="ClickAction" default="click">
|
|
71
|
+
The mouse action, as for `element.click()`. `'hover'` doesn't move the mouse here; use [`testdriver.hover({ x, y })`](/hover) instead.
|
|
72
|
+
</ParamField>
|
|
73
|
+
</Expandable>
|
|
74
|
+
</ParamField>
|
|
103
75
|
|
|
104
76
|
```javascript
|
|
105
|
-
|
|
106
|
-
await
|
|
107
|
-
|
|
108
|
-
// Or use the dedicated method
|
|
109
|
-
await file.doubleClick();
|
|
77
|
+
await testdriver.click({ x: 640, y: 360 });
|
|
78
|
+
await testdriver.click({ x: 640, y: 360, action: 'right-click' });
|
|
110
79
|
```
|
|
111
80
|
|
|
112
|
-
|
|
81
|
+
<Note>
|
|
82
|
+
The older form `testdriver.click(x, y, action)` still works. Use the options object in new tests.
|
|
83
|
+
</Note>
|
|
113
84
|
|
|
114
|
-
|
|
85
|
+
## Examples
|
|
115
86
|
|
|
116
|
-
|
|
117
|
-
const folder = await testdriver.find('Documents folder');
|
|
118
|
-
await folder.click('right-click');
|
|
87
|
+
### Open a context menu
|
|
119
88
|
|
|
120
|
-
|
|
121
|
-
await
|
|
89
|
+
```javascript
|
|
90
|
+
await testdriver.find('report.pdf in the file list').click('right-click');
|
|
91
|
+
await testdriver.find('Rename in the context menu').click();
|
|
122
92
|
```
|
|
123
93
|
|
|
124
|
-
###
|
|
125
|
-
|
|
126
|
-
Use these for drag operations or custom click behavior.
|
|
94
|
+
### Open a file
|
|
127
95
|
|
|
128
96
|
```javascript
|
|
129
|
-
|
|
130
|
-
await draggable.click('mouseDown');
|
|
131
|
-
|
|
132
|
-
// Move to target
|
|
133
|
-
const dropZone = await testdriver.find('drop zone');
|
|
134
|
-
await dropZone.hover();
|
|
135
|
-
await dropZone.click('mouseUp');
|
|
136
|
-
|
|
137
|
-
// Or use dedicated methods
|
|
138
|
-
await draggable.mouseDown();
|
|
139
|
-
await dropZone.mouseUp();
|
|
97
|
+
await testdriver.find('report.pdf in the file list').click('double-click');
|
|
140
98
|
```
|
|
141
99
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
<Check>
|
|
145
|
-
**Prefer element clicks to coordinate clicks**
|
|
146
|
-
|
|
147
|
-
A click on an element is more reliable. It does not depend on the resolution:
|
|
148
|
-
|
|
149
|
-
```javascript
|
|
150
|
-
// ✅ Preferred
|
|
151
|
-
const button = await testdriver.find('submit button');
|
|
152
|
-
await button.click();
|
|
153
|
-
|
|
154
|
-
// ❌ Avoid (fragile)
|
|
155
|
-
await testdriver.click(500, 300);
|
|
156
|
-
```
|
|
157
|
-
</Check>
|
|
158
|
-
|
|
159
|
-
<Check>
|
|
160
|
-
**Make sure that TestDriver found the element**
|
|
161
|
-
|
|
162
|
-
```javascript
|
|
163
|
-
const element = await testdriver.find('button');
|
|
164
|
-
if (!element.found()) {
|
|
165
|
-
throw new Error('Element not found');
|
|
166
|
-
}
|
|
167
|
-
await element.click();
|
|
168
|
-
```
|
|
169
|
-
</Check>
|
|
170
|
-
|
|
171
|
-
<Warning>
|
|
172
|
-
**TestDriver must find the element before you click it**
|
|
173
|
-
|
|
174
|
-
The `find()` method finds elements automatically. But a click on an element that TestDriver did not find throws an error:
|
|
175
|
-
|
|
176
|
-
```javascript
|
|
177
|
-
const element = await testdriver.find('button');
|
|
178
|
-
// This will throw if element wasn't found
|
|
179
|
-
await element.click();
|
|
180
|
-
```
|
|
181
|
-
</Warning>
|
|
182
|
-
|
|
183
|
-
## Use Cases
|
|
184
|
-
|
|
185
|
-
<AccordionGroup>
|
|
186
|
-
<Accordion title="Button Clicks">
|
|
187
|
-
```javascript
|
|
188
|
-
const submitBtn = await testdriver.find('submit button');
|
|
189
|
-
await submitBtn.click();
|
|
190
|
-
|
|
191
|
-
const cancelBtn = await testdriver.find('cancel button');
|
|
192
|
-
await cancelBtn.click();
|
|
193
|
-
```
|
|
194
|
-
</Accordion>
|
|
195
|
-
|
|
196
|
-
<Accordion title="Opening Files">
|
|
197
|
-
```javascript
|
|
198
|
-
const file = await testdriver.find('report.pdf file icon');
|
|
199
|
-
await file.doubleClick();
|
|
200
|
-
```
|
|
201
|
-
</Accordion>
|
|
202
|
-
|
|
203
|
-
<Accordion title="Context Menus">
|
|
204
|
-
```javascript
|
|
205
|
-
const item = await testdriver.find('file item');
|
|
206
|
-
await item.rightClick();
|
|
207
|
-
|
|
208
|
-
// Select menu option
|
|
209
|
-
const deleteOption = await testdriver.find('Delete option');
|
|
210
|
-
await deleteOption.click();
|
|
211
|
-
```
|
|
212
|
-
</Accordion>
|
|
213
|
-
|
|
214
|
-
<Accordion title="Drag and Drop">
|
|
215
|
-
```javascript
|
|
216
|
-
const source = await testdriver.find('source item');
|
|
217
|
-
await source.mouseDown();
|
|
218
|
-
|
|
219
|
-
const target = await testdriver.find('target zone');
|
|
220
|
-
await target.hover();
|
|
221
|
-
await target.mouseUp();
|
|
222
|
-
```
|
|
223
|
-
</Accordion>
|
|
224
|
-
</AccordionGroup>
|
|
225
|
-
|
|
226
|
-
## Complete Example
|
|
100
|
+
### Drag an item
|
|
227
101
|
|
|
228
102
|
```javascript
|
|
229
|
-
|
|
230
|
-
|
|
103
|
+
await testdriver.find('Task card titled "Write docs"').mouseDown();
|
|
104
|
+
await testdriver.find('Done column').hover();
|
|
105
|
+
await testdriver.find('Done column').mouseUp();
|
|
106
|
+
```
|
|
231
107
|
|
|
232
|
-
|
|
233
|
-
let testdriver;
|
|
108
|
+
## Complete example
|
|
234
109
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
await testdriver.connect();
|
|
239
|
-
});
|
|
110
|
+
```javascript tests/login.test.mjs
|
|
111
|
+
import { describe, expect, it } from 'vitest';
|
|
112
|
+
import { TestDriver } from 'testdriverai/vitest/hooks';
|
|
240
113
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
114
|
+
describe('Login', () => {
|
|
115
|
+
it('shows an error for an empty form', async (context) => {
|
|
116
|
+
const testdriver = TestDriver(context);
|
|
117
|
+
await testdriver.provision.chrome({ url: 'https://testdriver-sandbox.vercel.app/login' });
|
|
244
118
|
|
|
245
|
-
|
|
246
|
-
await testdriver.focusApplication('Google Chrome');
|
|
247
|
-
|
|
248
|
-
// Regular click
|
|
249
|
-
const loginBtn = await testdriver.find('login button');
|
|
250
|
-
await loginBtn.click();
|
|
251
|
-
|
|
252
|
-
// Right-click for context menu
|
|
253
|
-
const profileIcon = await testdriver.find('profile icon');
|
|
254
|
-
await profileIcon.rightClick();
|
|
255
|
-
|
|
256
|
-
const settingsOption = await testdriver.find('Settings menu option');
|
|
257
|
-
await settingsOption.click();
|
|
258
|
-
|
|
259
|
-
// Double-click to edit
|
|
260
|
-
const nameField = await testdriver.find('name display field');
|
|
261
|
-
await nameField.doubleClick();
|
|
262
|
-
|
|
263
|
-
// Verify state
|
|
264
|
-
await testdriver.assert('name field is now editable');
|
|
265
|
-
});
|
|
119
|
+
await testdriver.find('Sign in button below the password field').click();
|
|
266
120
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
await item.mouseDown();
|
|
270
|
-
|
|
271
|
-
// Drag to new location
|
|
272
|
-
const dropTarget = await testdriver.find('drop area');
|
|
273
|
-
await dropTarget.hover();
|
|
274
|
-
await dropTarget.mouseUp();
|
|
275
|
-
|
|
276
|
-
// Verify
|
|
277
|
-
await testdriver.assert('item is in the drop area');
|
|
121
|
+
const result = await testdriver.assert('an error says the fields are required');
|
|
122
|
+
expect(result).toBe(true);
|
|
278
123
|
});
|
|
279
124
|
});
|
|
280
125
|
```
|
|
281
126
|
|
|
282
|
-
## Related
|
|
127
|
+
## Related
|
|
283
128
|
|
|
284
|
-
- [
|
|
285
|
-
- [
|
|
286
|
-
- [
|
|
287
|
-
- [
|
|
129
|
+
- [find()](/find): locate the element to click
|
|
130
|
+
- [doubleClick()](/double-click), [rightClick()](/right-click), and [hover()](/hover): shortcuts for the other actions
|
|
131
|
+
- [mouseDown()](/mouse-down) and [mouseUp()](/mouse-up): drag and drop
|
|
132
|
+
- [Perform actions](/performing-actions): every kind of action in one guide
|