Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting screen size in PhantomJS C# being driven by Selenium

How do I set the browser screen size? When I take a screen shot after setting up PhantomJS as below its only showing a 400px wide image.

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

using (var driver = new PhantomJSDriver(driverService))
{
    etc....
}
like image 574
John Avatar asked Dec 25 '22 08:12

John


1 Answers

It should be the same as setting window size in any other browsers, feel free to have a look at this example: How to get window size, resize or maximize window using Selenium WebDriver.

Here is the code tested working for me:

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);
}
like image 78
Yi Zeng Avatar answered Dec 28 '22 13:12

Yi Zeng