2021-01-07 11:46:05 -08:00
|
|
|
# class: FileChooser
|
|
|
|
|
2021-02-04 19:34:09 +01:00
|
|
|
[FileChooser] objects are dispatched by the page in the [`event: Page.fileChooser`] event.
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
```js
|
2022-01-13 10:38:22 -08:00
|
|
|
// Note that Promise.all prevents a race condition
|
|
|
|
// between clicking and waiting for the file chooser.
|
2021-01-20 08:12:39 -08:00
|
|
|
const [fileChooser] = await Promise.all([
|
2022-01-13 10:38:22 -08:00
|
|
|
// It is important to call waitForEvent before click to set up waiting.
|
2021-01-20 08:12:39 -08:00
|
|
|
page.waitForEvent('filechooser'),
|
2022-01-13 10:38:22 -08:00
|
|
|
// Opens the file chooser.
|
|
|
|
page.locator('text=Upload').click(),
|
2021-01-20 08:12:39 -08:00
|
|
|
]);
|
|
|
|
await fileChooser.setFiles('myfile.pdf');
|
2021-01-07 11:46:05 -08:00
|
|
|
```
|
|
|
|
|
2021-02-25 22:03:39 -08:00
|
|
|
```java
|
|
|
|
FileChooser fileChooser = page.waitForFileChooser(() -> page.click("upload"));
|
|
|
|
fileChooser.setFiles(Paths.get("myfile.pdf"));
|
|
|
|
```
|
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
```python async
|
2021-01-20 08:12:39 -08:00
|
|
|
async with page.expect_file_chooser() as fc_info:
|
|
|
|
await page.click("upload")
|
|
|
|
file_chooser = await fc_info.value
|
|
|
|
await file_chooser.set_files("myfile.pdf")
|
2021-01-14 07:48:56 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
2021-01-20 08:12:39 -08:00
|
|
|
with page.expect_file_chooser() as fc_info:
|
|
|
|
page.click("upload")
|
|
|
|
file_chooser = fc_info.value
|
|
|
|
file_chooser.set_files("myfile.pdf")
|
2021-01-14 07:48:56 -08:00
|
|
|
```
|
|
|
|
|
2021-05-13 19:24:15 +02:00
|
|
|
```csharp
|
2021-05-26 15:11:31 -07:00
|
|
|
var fileChooser = await page.RunAndWaitForFileChooserAsync(async () =>
|
2021-05-19 17:19:25 -07:00
|
|
|
{
|
|
|
|
await page.ClickAsync("upload");
|
|
|
|
});
|
2021-05-15 14:02:07 -07:00
|
|
|
await fileChooser.SetFilesAsync("temp.txt");
|
2021-05-13 19:24:15 +02:00
|
|
|
```
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
## method: FileChooser.element
|
|
|
|
- returns: <[ElementHandle]>
|
|
|
|
|
|
|
|
Returns input element associated with this file chooser.
|
|
|
|
|
|
|
|
## method: FileChooser.isMultiple
|
|
|
|
- returns: <[boolean]>
|
|
|
|
|
|
|
|
Returns whether this file chooser accepts multiple files.
|
|
|
|
|
|
|
|
## method: FileChooser.page
|
|
|
|
- returns: <[Page]>
|
|
|
|
|
|
|
|
Returns page this file chooser belongs to.
|
|
|
|
|
|
|
|
## async method: FileChooser.setFiles
|
|
|
|
|
|
|
|
Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, then
|
2022-04-27 16:06:30 +02:00
|
|
|
they are resolved relative to the current working directory. For empty array, clears the selected files.
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
### param: FileChooser.setFiles.files = %%-input-files-%%
|
|
|
|
|
|
|
|
### option: FileChooser.setFiles.noWaitAfter = %%-input-no-wait-after-%%
|
|
|
|
|
|
|
|
### option: FileChooser.setFiles.timeout = %%-input-timeout-%%
|