2021-01-07 11:46:05 -08:00
|
|
|
# class: FileChooser
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
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-11-30 12:36:35 -08:00
|
|
|
// Start waiting for file chooser before clicking. Note no await.
|
|
|
|
const fileChooserPromise = page.waitForEvent('filechooser');
|
|
|
|
await page.getByText('Upload file').click();
|
|
|
|
const fileChooser = await fileChooserPromise;
|
2023-08-22 17:38:23 +02:00
|
|
|
await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf'));
|
2021-01-07 11:46:05 -08:00
|
|
|
```
|
|
|
|
|
2021-02-25 22:03:39 -08:00
|
|
|
```java
|
2022-11-30 12:36:35 -08:00
|
|
|
FileChooser fileChooser = page.waitForFileChooser(() -> page.getByText("Upload file").click());
|
2021-02-25 22:03:39 -08:00
|
|
|
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:
|
2022-11-30 12:36:35 -08:00
|
|
|
await page.get_by_text("Upload file").click()
|
2021-01-20 08:12:39 -08:00
|
|
|
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:
|
2022-11-30 12:36:35 -08:00
|
|
|
page.get_by_text("Upload file").click()
|
2021-01-20 08:12:39 -08:00
|
|
|
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
|
|
|
{
|
2022-11-30 12:36:35 -08:00
|
|
|
await page.GetByText("Upload file").ClickAsync();
|
2021-05-19 17:19:25 -07:00
|
|
|
});
|
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
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
- returns: <[ElementHandle]>
|
|
|
|
|
|
|
|
Returns input element associated with this file chooser.
|
|
|
|
|
|
|
|
## method: FileChooser.isMultiple
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
- returns: <[boolean]>
|
|
|
|
|
|
|
|
Returns whether this file chooser accepts multiple files.
|
|
|
|
|
|
|
|
## method: FileChooser.page
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
- returns: <[Page]>
|
|
|
|
|
|
|
|
Returns page this file chooser belongs to.
|
|
|
|
|
|
|
|
## async method: FileChooser.setFiles
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
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-%%
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
2024-07-18 00:19:08 -07:00
|
|
|
### option: FileChooser.setFiles.noWaitAfter = %%-input-no-wait-after-removed-%%
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
### option: FileChooser.setFiles.timeout = %%-input-timeout-%%
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2023-03-14 16:34:30 -07:00
|
|
|
|
|
|
|
### option: FileChooser.setFiles.timeout = %%-input-timeout-js-%%
|
|
|
|
* since: v1.8
|