C# - Screen resolution Not Working With Selenium Chrome Web Driver

Viewed 408

I am using chrome web driver (93.0.4577.63) with selenium (3.141.0) on chrome browser (93.0.4577.82). What I'm trying to do is changing the screen resolution when I access a website , but it is not working. My code is :

IWebDriver driver;
        public MainWindow()
        {
            InitializeComponent();
           
            ChromeOptions op = new ChromeOptions();

            op.AddAdditionalCapability("screen-resolution", "-screenwidth 1024 -screenheight 768", true);
          
            op.AddArgument("incognito");
            op.AddArgument("--window-size=771,360");
            op.AddArgument("window-size=771,360");
            
           
            driver = new ChromeDriver(op);
            
            driver.Navigate().GoToUrl("https://bestfirms.com/what-is-my-screen-resolution/");
          
         
         

        }

my main screen resolution is 1920X1080 . When I try to access a site to check if it changed to another resolution (771X360) it does not work.

can you please point me at what I'm doing wrong ?

Thanks

Edit : I have also tried

driver.Manage().Window.Size = new System.Drawing.Size(771, 360);

still no luck :(

1 Answers

Can you try this :

ChromeOptions op = new ChromeOptions();
op.AddArgument("--incognito");
op.AddArgument("--window-size=1920,1080");
op.AddArgument("--start-maximized");
driver = new ChromeDriver(op);

Possibly your script needed --incognito not only incognito.

PS If the above one work then, You can change this --window-size=1920,1080 to --window-size=771,360

Related