0

I got an annoying issue here. My setup is as follows: Windows Server 2022 Data Center running as a VM in Azure. I have a windows service running that is using selenium Chrome Webdriver to open a local page and it exports a pdf from a button click. This works fine but the resolution of the pdf is terrible because the window size of the browser is only 1024 x 768 due to it being in a windows service context I've been reading, almost like a headless server with no screen.

Now I've tried:

  • In my Chrome webdriver code to maximize the window, set various window sizes, nothing yet works for the windows service. (This works fine when not running as a windows service, the window sizes change accordingly)
  • Been looking at registry entries such as ones from here: https://superuser.com/questions/990398/setting-display-resolution-beyond-1024x768-with-headless-windows-10
  • I can simulate this behaviour on my local machine too
  • Tried the "Allow service to interact with desktop" but no luck
  • Ran Chrome Webdriver in "headless" mode but was causing issues with the export of the pdf, anyone know if this would allow setting your window size?
  • Ran as a Scheduled Windows task, still runs at same 1024 x 768
  • I've looked at SO's suggested similar questions

Obviously running this as As a Different User which is the service account works and the browser expands to maximized size but that's because it's not in a windows service context. I'm going to try run the app in a few different ways from a different app launching it running itself as a windows service account as in a new windows service trying to launch my current app.

Has anyone ever encountered or sorted out such an issue with locked resolution of 1024 x 768 while using a service account? Thanx all!

jjay225
  • 508
  • 6
  • 12

1 Answers1

0

Found the solution!

So after trying the above, no reg edits worked, no other virtual display adapter worked. I changed the headless code I had to the answer from this kind chap: https://stackoverflow.com/a/65397605/1426131 and it works perflectly! Can set any window size I want. Previous iterations of the headless chrome webdriver code I had didn't work.

This will work locally on Windows 10 as well so it's easy to test if anyone is having a similar issue.

UPDATE Adding code below from link above:

public IWebDriver GetBrowserWebDriver(string browser)
    {
        IWebDriver currentDriver = null;        
        switch (browser)
        {
            case "Chrome":                    
                var options = new ChromeOptions();
                options.AddArgument("headless");
                string downloadPath = System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\Downloads";
                options.AddUserProfilePreference("download.default_directory", downloadPath);
                options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
                options.AddArgument("--window-size=1920,1080");                    
                currentDriver = new ChromeDriver(options);
                break;
            case "Firefox":
                currentDriver = new FirefoxDriver();
                break;
            case "IE":
                currentDriver = new InternetExplorerDriver(new InternetExplorerOptions() { IgnoreZoomLevel = true });
                break;
            default:
                throw new NotSupportedException("");
        }
        return currentDriver;
    }

So how I currently use it is:

  using (var driver = GetBrowserWebDriver("Chrome"))
  {}
jjay225
  • 508
  • 6
  • 12
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/32337112) – zozo Jul 26 '22 at 12:36
  • 2
    I get you man, lemme include that actual code for other peeps. Thanx zozo – jjay225 Jul 26 '22 at 15:39