How to open a browser window in full screen using Selenium WebDriver with C#?

We can open a browser window in full screen using Selenium WebDriver in C# by using the Maximize() method. This method is applied on the WebDriver object through the window management interface and expands the browser to fill the entire screen.

Syntax

Following is the syntax for maximizing a browser window −

driver.Manage().Window.Maximize();

For setting specific window size, you can also use −

driver.Manage().Window.Size = new Size(width, height);

Using Maximize() Method

The Maximize() method is the most common approach to open a browser in full screen mode. It automatically adjusts the browser window to occupy the entire available screen space −

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program {
   public static void Main() {
      IWebDriver driver = new ChromeDriver();
      
      try {
         // Navigate to URL
         driver.Navigate().GoToUrl("https://www.google.com/");
         
         // Maximize browser window
         driver.Manage().Window.Maximize();
         Console.WriteLine("Browser window maximized successfully");
         
         // Get window size after maximizing
         var size = driver.Manage().Window.Size;
         Console.WriteLine($"Window size: {size.Width} x {size.Height}");
         
         System.Threading.Thread.Sleep(3000); // Wait 3 seconds
      }
      finally {
         driver.Quit();
      }
   }
}

The output of the above code is −

Browser window maximized successfully
Window size: 1920 x 1080

Using FullScreen() Method

Selenium also provides a FullScreen() method which puts the browser in true full screen mode, similar to pressing F11 −

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program {
   public static void Main() {
      IWebDriver driver = new ChromeDriver();
      
      try {
         driver.Navigate().GoToUrl("https://www.example.com/");
         
         // Put browser in full screen mode
         driver.Manage().Window.FullScreen();
         Console.WriteLine("Browser in full screen mode");
         
         System.Threading.Thread.Sleep(3000); // Wait 3 seconds
      }
      finally {
         driver.Quit();
      }
   }
}

The output of the above code is −

Browser in full screen mode

Setting Custom Window Size

You can also set a specific window size instead of maximizing −

using System;
using System.Drawing;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program {
   public static void Main() {
      IWebDriver driver = new ChromeDriver();
      
      try {
         driver.Navigate().GoToUrl("https://www.tutorialspoint.com/");
         
         // Set custom window size
         driver.Manage().Window.Size = new Size(1366, 768);
         Console.WriteLine("Custom window size set: 1366x768");
         
         // Get current window position and size
         var size = driver.Manage().Window.Size;
         var position = driver.Manage().Window.Position;
         Console.WriteLine($"Size: {size.Width}x{size.Height}, Position: ({position.X}, {position.Y})");
         
         System.Threading.Thread.Sleep(2000);
      }
      finally {
         driver.Quit();
      }
   }
}

The output of the above code is −

Custom window size set: 1366x768
Size: 1366x768, Position: (0, 0)

Comparison of Window Management Methods

Method Description Use Case
Maximize() Maximizes window to fit screen with title bar visible Most common for testing, maintains OS controls
FullScreen() True full screen mode, hides title bar and taskbar Kiosk mode applications, immersive testing
Size = new Size() Sets specific width and height dimensions Testing responsive design, specific resolutions

Conclusion

Selenium WebDriver provides multiple methods to control browser window size in C#. The Maximize() method is most commonly used for test automation, while FullScreen() provides true full screen experience. Custom sizing allows precise control for responsive testing scenarios.

Updated on: 2026-03-17T07:04:36+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements