设置phantomjs c#中的屏幕尺寸由硒驱动[英] Setting screen size in PhantomJS C# being driven by Selenium

问题描述

如何设置浏览器屏幕大小?当我在设置phantomjs之后进行屏幕截图时,仅显示400px宽的图像.

var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
driverService.LoadImages = false;
driverService.ProxyType = "none";      

using (var driver = new PhantomJSDriver(driverService))
{
    etc....
}

推荐答案

它应该与其他任何浏览器中的窗口大小相同,请随时查看此示例:如何获得窗口大小,使用Selenium web Driver <.

这是对我工作的代码:

var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
driverService.LoadImages = false;
driverService.ProxyType = "none";

using (var driver = new PhantomJSDriver(driverService)) {
    driver.Manage().Window.Size = new Size(1920, 1080); // Size is a type in assembly "System.Drawing"
    driver.Url = "http://www.stackoverflow.com";
    driver.TakeScreenshot().SaveAsFile(@"c:\phantomjs_screenshot.png", ImageFormat.Png);
}

本文地址:https://www.itbaoku.cn/post/1739850.html