Skip to content

Commit 47de979

Browse files
authored
chore(docs): doc for fileChooserAccept in yaml (#2273)
1 parent 6d9705f commit 47de979

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

apps/site/docs/en/automate-with-scripts-in-yaml.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ tasks:
454454
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
455455
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
456456
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
457+
fileChooserAccept: <path> | [<path1>, <path2>] # Optional, file path(s) to upload when the tap triggers a file chooser; only available on web
457458

458459
# Hover over an element described by a prompt.
459460
- aiHover: <prompt>
@@ -519,6 +520,43 @@ tasks:
519520
# ...
520521
```
521522

523+
#### Upload Files With `aiTap`
524+
525+
When clicking a button opens a file chooser, you can set `fileChooserAccept` directly on the `aiTap` step. It accepts either a single path or an array of paths.
526+
527+
```yaml
528+
tasks:
529+
- name: upload single file
530+
flow:
531+
- aiTap: Choose file button
532+
fileChooserAccept: ./fixtures/document.pdf
533+
534+
- name: upload multiple files
535+
flow:
536+
- aiTap: Upload images button
537+
fileChooserAccept:
538+
- ./fixtures/image1.jpg
539+
- ./fixtures/image2.png
540+
```
541+
542+
If you are already using a `locate` object for `prompt`, `images`, or other locate options, keep `fileChooserAccept` at the same level as `locate`. Do not nest it inside `locate` or inside the `aiTap` object:
543+
544+
```yaml
545+
tasks:
546+
- name: upload file with locate
547+
flow:
548+
- aiTap:
549+
locate:
550+
prompt: Click the upload button
551+
fileChooserAccept: ./fixtures/document.pdf
552+
```
553+
554+
Notes:
555+
556+
- `fileChooserAccept` is only available for web pages (Playwright, Puppeteer).
557+
- Relative paths are resolved from the current command working directory, not from the YAML file directory.
558+
- If a file does not exist, the script throws before the tap is executed.
559+
522560
#### Prompting with images
523561

524562
For steps whose prompt accepts images, you can attach images to the prompt by setting the `images` field to an array of objects, each containing a `name` and a `url`. (see the [API reference](./api#prompting-with-images)), replace the string value with an object that contains:

apps/site/docs/zh/automate-with-scripts-in-yaml.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ tasks:
458458
deepThink: <boolean> # 可选,是否使用深度思考(deepThink)来精确定位元素。默认值为 False
459459
xpath: <xpath> # 可选,目标元素的 xpath 路径,用于执行当前操作。如果提供了这个 xpath,Midscene 会优先使用该 xpath 来找到元素,然后依次使用缓存和 AI 模型。默认值为空
460460
cacheable: <boolean> # 可选,当启用 [缓存功能](./caching.mdx) 时,是否允许缓存当前 API 调用结果。默认值为 True
461+
fileChooserAccept: <path> | [<path1>, <path2>] # 可选,当点击触发文件选择器时,指定要上传的文件路径;仅在 web 中可用
461462

462463
# 鼠标悬停一个元素,用 prompt 描述元素位置
463464
- aiHover: <prompt>
@@ -526,6 +527,43 @@ tasks:
526527
# ...
527528
```
528529

530+
#### 使用 `aiTap` 上传文件
531+
532+
当点击某个按钮会弹出文件选择器时,可以在 `aiTap` 步骤上直接设置 `fileChooserAccept`。它支持单个路径,也支持路径数组。
533+
534+
```yaml
535+
tasks:
536+
- name: 上传单个文件
537+
flow:
538+
- aiTap: 选择文件按钮
539+
fileChooserAccept: ./fixtures/document.pdf
540+
541+
- name: 上传多个文件
542+
flow:
543+
- aiTap: 上传图片按钮
544+
fileChooserAccept:
545+
- ./fixtures/image1.jpg
546+
- ./fixtures/image2.png
547+
```
548+
549+
如果你已经在用 `locate` 对象写 `prompt`、`images` 等定位信息,`fileChooserAccept` 仍然要和 `locate` 保持同级,不要放到 `locate` 或 `aiTap` 的嵌套对象里:
550+
551+
```yaml
552+
tasks:
553+
- name: 带 locate 的文件上传
554+
flow:
555+
- aiTap:
556+
locate:
557+
prompt: 点击上传按钮
558+
fileChooserAccept: ./fixtures/document.pdf
559+
```
560+
561+
注意:
562+
563+
- `fileChooserAccept` 仅在 web 页面(Playwright、Puppeteer)中可用。
564+
- 相对路径会基于当前命令执行目录解析,而不是基于 YAML 文件所在目录解析。
565+
- 如果文件不存在,脚本会在执行点击前直接报错。
566+
529567
#### 使用图像提示
530568

531569
对于支持在提示词中附带图像的步骤(参见 [API 参考](./api#prompting-with-images)),可以把提示词改写为对象,并通过设置 `images` 字段(一个包含 `name` 和 `url` 的对象数组)来附加图像。该对象包含以下字段:

0 commit comments

Comments
 (0)