Setting screen size in PhantomJS C # managed by Selenium

How to set browser screen size? When I take a screenshot after setting up PhantomJS as shown below, it only shows an image 400 pixels wide.

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

using (var driver = new PhantomJSDriver(driverService))
{
    etc....
}
+4
source share
1 answer

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

Here is the code that works 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);
}
+10
source

Source: https://habr.com/ru/post/1541837/


All Articles