Skip to content

Commit d6b98ef

Browse files
authored
docs(dotnet): examples for dialog, download and filechooser (#6526)
1 parent 8b6b894 commit d6b98ef

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

docs/src/api/class-dialog.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ with sync_playwright() as playwright:
8080
run(playwright)
8181
```
8282

83+
```csharp
84+
using Microsoft.Playwright;
85+
using System.Threading.Tasks;
86+
87+
class DialogExample
88+
{
89+
public static async Task Run()
90+
{
91+
using var playwright = await Playwright.CreateAsync();
92+
await using var browser = await playwright.Chromium.LaunchAsync();
93+
var page = await browser.NewPageAsync();
94+
95+
page.Dialog += async (_, dialog) =>
96+
{
97+
System.Console.WriteLine(dialog.Message);
98+
await dialog.DismissAsync();
99+
};
100+
101+
await page.EvaluateAsync("alert('1');");
102+
}
103+
}
104+
```
105+
83106
:::note
84107
Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener.
85108
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.

docs/src/api/class-download.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ download = download_info.value
4848
path = download.path()
4949
```
5050

51+
```csharp
52+
var downloadTask = page.WaitForDownloadAsync();
53+
await Task.WhenAll(downloadTask, page.ClickAsync("#downloadButton"));
54+
Console.WriteLine(await downloadTask.Result.PathAsync());
55+
```
56+
5157
:::note
5258
Browser context **must** be created with the [`option: acceptDownloads`] set to `true` when user needs access to the
5359
downloaded content. If [`option: acceptDownloads`] is not set, download events are emitted, but the actual download is
@@ -96,4 +102,4 @@ browsers can use different logic for computing it.
96102
## method: Download.url
97103
- returns: <[string]>
98104

99-
Returns downloaded url.
105+
Returns downloaded url.

docs/src/api/class-filechooser.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ file_chooser = fc_info.value
2929
file_chooser.set_files("myfile.pdf")
3030
```
3131

32+
```csharp
33+
var fileChooserTask = page.WaitForFileChooserAsync();
34+
await Task.WhenAll(fileChooserTask, page.ClickAsync("upload"));
35+
await fileChooserTask.Result.SetFilesAsync("temp.txt");
36+
```
37+
3238
## method: FileChooser.element
3339
- returns: <[ElementHandle]>
3440

0 commit comments

Comments
 (0)