Setting screen size in PhantomJS C# being driven by Selenium

前端 未结 1 1080
终归单人心
终归单人心 2020-12-19 16:12

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 =          


        
相关标签:
1条回答
  • 2020-12-19 16:51

    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);
    }
    
    0 讨论(0)
提交回复
热议问题