FileChooser
FileChooser 对象由 Page.FileChooser 事件中的页面调度。
¥FileChooser objects are dispatched by the page in the Page.FileChooser event.
var fileChooser = await page.RunAndWaitForFileChooserAsync(async () =>
{
await page.GetByText("Upload file").ClickAsync();
});
await fileChooser.SetFilesAsync("temp.txt");
方法
¥Methods
元素
¥Element
Added before v1.9返回与此文件选择器关联的输入元素。
¥Returns input element associated with this file chooser.
用法
¥Usage
FileChooser.Element
返回
¥Returns
IsMultiple
Added before v1.9返回此文件选择器是否接受多个文件。
¥Returns whether this file chooser accepts multiple files.
用法
¥Usage
FileChooser.IsMultiple
返回
¥Returns
Page
Added before v1.9返回此文件选择器所属的页面。
¥Returns page this file chooser belongs to.
用法
¥Usage
FileChooser.Page
返回
¥Returns
SetFilesAsync
Added before v1.9设置与此选择器关联的文件输入的值。如果某些 filePaths
是相对路径,则它们将相对于当前工作目录进行解析。对于空数组,清除选定的文件。
¥Sets the value of the file input this chooser is associated with. If some of the filePaths
are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.
用法
¥Usage
await FileChooser.SetFilesAsync(files, options);
参数
¥Arguments
-
files
string | IEnumerable<string> |FilePayload
| IEnumerable<FilePayload
>#Name
string
文件名
¥File name
MimeType
string
文件类型
¥File type
Buffer
byte[]
文件内容
¥File content
-
options
FileChooserSetFilesOptions?
(可选)¥
options
FileChooserSetFilesOptions?
(optional)
This option has no effect.
此选项无效。
¥This option has no effect.
Timeout
[float]? (optional)#
最长时间(以毫秒为单位)。默认为 30000
(30 秒)。通过 0
禁用超时。可以使用 BrowserContext.SetDefaultTimeout() 或 Page.SetDefaultTimeout() 方法更改默认值。
¥Maximum time in milliseconds. Defaults to 30000
(30 seconds). Pass 0
to disable timeout. The default value can be changed by using the BrowserContext.SetDefaultTimeout() or Page.SetDefaultTimeout() methods.
返回
¥Returns