docs(dotnet): examples for dialog, download and filechooser (#6526)
This commit is contained in:
parent
8b6b894dd8
commit
d6b98effc3
|
|
@ -80,6 +80,29 @@ with sync_playwright() as playwright:
|
||||||
run(playwright)
|
run(playwright)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using Microsoft.Playwright;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
class DialogExample
|
||||||
|
{
|
||||||
|
public static async Task Run()
|
||||||
|
{
|
||||||
|
using var playwright = await Playwright.CreateAsync();
|
||||||
|
await using var browser = await playwright.Chromium.LaunchAsync();
|
||||||
|
var page = await browser.NewPageAsync();
|
||||||
|
|
||||||
|
page.Dialog += async (_, dialog) =>
|
||||||
|
{
|
||||||
|
System.Console.WriteLine(dialog.Message);
|
||||||
|
await dialog.DismissAsync();
|
||||||
|
};
|
||||||
|
|
||||||
|
await page.EvaluateAsync("alert('1');");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener.
|
Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener.
|
||||||
When listener is present, it **must** either [`method: Dialog.accept`] or [`method: Dialog.dismiss`] the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.
|
When listener is present, it **must** either [`method: Dialog.accept`] or [`method: Dialog.dismiss`] the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@ download = download_info.value
|
||||||
path = download.path()
|
path = download.path()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var downloadTask = page.WaitForDownloadAsync();
|
||||||
|
await Task.WhenAll(downloadTask, page.ClickAsync("#downloadButton"));
|
||||||
|
Console.WriteLine(await downloadTask.Result.PathAsync());
|
||||||
|
```
|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
Browser context **must** be created with the [`option: acceptDownloads`] set to `true` when user needs access to the
|
Browser context **must** be created with the [`option: acceptDownloads`] set to `true` when user needs access to the
|
||||||
downloaded content. If [`option: acceptDownloads`] is not set, download events are emitted, but the actual download is
|
downloaded content. If [`option: acceptDownloads`] is not set, download events are emitted, but the actual download is
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,12 @@ file_chooser = fc_info.value
|
||||||
file_chooser.set_files("myfile.pdf")
|
file_chooser.set_files("myfile.pdf")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var fileChooserTask = page.WaitForFileChooserAsync();
|
||||||
|
await Task.WhenAll(fileChooserTask, page.ClickAsync("upload"));
|
||||||
|
await fileChooserTask.Result.SetFilesAsync("temp.txt");
|
||||||
|
```
|
||||||
|
|
||||||
## method: FileChooser.element
|
## method: FileChooser.element
|
||||||
- returns: <[ElementHandle]>
|
- returns: <[ElementHandle]>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue