mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
1.9 KiB
1.9 KiB
class: FileChooser
[FileChooser] objects are dispatched by the page in the [event: Page.fileChooser
] event.
// Note that Promise.all prevents a race condition
// between clicking and waiting for the file chooser.
const [fileChooser] = await Promise.all([
// It is important to call waitForEvent before click to set up waiting.
page.waitForEvent('filechooser'),
// Opens the file chooser.
page.locator('text=Upload').click(),
]);
await fileChooser.setFiles('myfile.pdf');
FileChooser fileChooser = page.waitForFileChooser(() -> page.click("upload"));
fileChooser.setFiles(Paths.get("myfile.pdf"));
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")
with page.expect_file_chooser() as fc_info:
page.click("upload")
file_chooser = fc_info.value
file_chooser.set_files("myfile.pdf")
var fileChooser = await page.RunAndWaitForFileChooserAsync(async () =>
{
await page.ClickAsync("upload");
});
await fileChooser.SetFilesAsync("temp.txt");
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
they are resolved relative to the current working directory. For empty array, clears the selected files.