From 12b258dc25b57e1c64e02e62480a962fbbabf314 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 19 Jun 2024 13:02:12 +0200 Subject: [PATCH] review feedback --- docs/src/dialogs.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/src/dialogs.md b/docs/src/dialogs.md index aac75097ff..20037245ee 100644 --- a/docs/src/dialogs.md +++ b/docs/src/dialogs.md @@ -129,49 +129,52 @@ await Page.CloseAsync(new() { RunBeforeUnload = true }); ## Print dialogs -In order to assert that a print dialog via [`window.print`](https://developer.mozilla.org/en-US/docs/Web/API/Window/print) was opened, you can use the following snippet: +In order to assert that a print dialog via [`window.print`](https://developer.mozilla.org/en-US/docs/Web/API/Window/print) was triggered, you can use the following snippet: ```js -await page.evaluate('(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()'); - await page.goto(''); + +await page.evaluate('(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()'); await page.getByText('Print it!').click(); await page.waitForFunction('window.waitForPrintDialog'); ``` ```java -page.evaluate("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()"); - page.navigate(""); + +page.evaluate("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()"); page.getByText("Print it!").click(); page.waitForFunction("window.waitForPrintDialog"); ``` ```python async -await page.evaluate("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()") - await page.goto("") + +await page.evaluate("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()") await page.get_by_text("Print it!").click() await page.wait_for_function("window.waitForPrintDialog") ``` ```python sync -page.evaluate("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()") - page.goto("") + +page.evaluate("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()") page.get_by_text("Print it!").click() page.wait_for_function("window.waitForPrintDialog") ``` ```csharp -await Page.EvaluateAsync("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()"); - await Page.GotoAsync(""); + +await Page.EvaluateAsync("(() => {window.waitForPrintDialog = new Promise(f => window.print = f);})()"); await Page.GetByText("Print it!").ClickAsync(); await Page.WaitForFunctionAsync("window.waitForPrintDialog"); ``` + +This will wait for the print dialog to be opened after the button is clicked. +Make sure to evaluate the script before clicking the button / after the page is loaded.