当尝试使用WebBrowser Controller为网页screenShots执行C#代码时,我得到的截图是由IE呈现的网页,而不是Chrome(我试图捕获的网站由Chrome,FireFox和IE)。
您能向我解释如何为Chrome浏览器呈现的网页制作屏幕截图吗? Ps:之前我使用过ChromeDriver,但它只捕获了网页的可见部分, 非常感谢
这是拍摄网页截屏的方法
`public static void TakeScreenShotChrome(WebBrowser WB, string url, string path)
// Load the webpage into a WebBrowser control WebBrowser
{
WB.ScrollBarsEnabled = false;
WB.ScriptErrorsSuppressed = true;
WB.Navigate(url);
while (WB.ReadyState != WebBrowserReadyState.Complete)
{
//Application.DoEvents();
Thread.Sleep(1000);
}
// Take Screenshot of the web pages full width
WB.Width = WB.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
WB.Height = WB.Document.Body.ScrollRectangle.Height;
Bitmap bitmap = new Bitmap(WB.Width, WB.Height);
WB.DrawToBitmap(bitmap, new Rectangle(0, 0, WB.Width, WB.Height));
bitmap.Save(path,ImageFormat.Png);
WB.Dispose();
}`