How to maximize the browser window in Selenium WebDriver using C#?


We can maximize the browser window with Selenium webdriver in C#. This can be done with the help of the Maximize method. We shall launch the browser and then apply this method on the driver object.

Syntax

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

For implementation we shall be using the NUnit framework.

Example

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace NUnitTestProject1{
   public class Tests{
      String u = "https://www.tutorialspoint.com/index.htm";
      IWebDriver d;
      [SetUp]
      public void Setup(){
         //creating object of FirefoxDriver
         d = new FirefoxDriver();
      }
      [Test]
      public void Test1(){
         //launching URL
         d.Navigate().GoToUrl(u);
         //maximizing browser
         d.Manage().Window.Maximize();
         Console.WriteLine("Browser Maximized");
      }
      [TearDown]
      public void close_Browser(){
         d.Quit();
      }
   }
}

Output

Click on Run All Tests

Then, click on Open additional output for this result link

Updated on: 30-Jan-2021

860 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements