From 8443d29bd20ea41948faa07539f9947664ba0dcc Mon Sep 17 00:00:00 2001 From: wanggaofeng <15601716045@163.com> Date: Wed, 31 Jan 2024 14:30:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaywrightStudy.Test/PlaywrightTest.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PlaywrightStudy.Test/PlaywrightTest.cs b/PlaywrightStudy.Test/PlaywrightTest.cs index 3527434..f103b5a 100644 --- a/PlaywrightStudy.Test/PlaywrightTest.cs +++ b/PlaywrightStudy.Test/PlaywrightTest.cs @@ -77,10 +77,24 @@ namespace PlaywrightStudy.Test await page.WaitForLoadStateAsync(); - //截图 + //页面截图 await page.ScreenshotAsync(new() { - Path = "Baidu.Edge.Screenshot.png" + Path = "Baidu.Edge.Screenshot.png", + FullPage = true, //整页截图 + }); + + //元素截图 + var paggerLocator = page.Locator("#page"); + + //无此行,则元素截图错误 + var paagerCount = await paggerLocator.CountAsync(); + + await paggerLocator.ScreenshotAsync(new LocatorScreenshotOptions() + { + Path = "Baidu.Edge.ByPage.Screenshot.png", + //Quality = 100, + Type = ScreenshotType.Png }); //网页保存为Pdf文件