In the previous article, I have explained – Maximizing the Browser Window.
In this article, I will explain Customizing the Browser window to a particular size using driver.Manage().Window().Size
Let’s get started.
Selenium C# – Maximizing the Browser
In this article, I am going to practically demonstrate by providing the task first followed by solution.
Task: Open the Chrome browser using Selenium C#, which opens the Browser in resized mode.
Wait for 5 seconds using Thread.Sleep() and then Maximize the browser using Manage(), Window and Maximize() Selenium C# API Commands.
Then navigate to http://omayo.blogspot.com URL using the previous explained Navigate().GoToURL()
Solution: Lets follow the below steps:
2) Write the WebDriverManager and ChromeDriver object creation statement as explained in the previous WebDriverManager post:
3) Now let’s write the below Selenium code to navigate to http://omayo.blogspot.com/ as shown below:
4) Let’s customize the chrome browser size page by adding driver.Manage().Window.Size to the code along with required x and y coordinates as shown below:
The below is the code for assigning the x and y coordinates to the browser size as an argument:
driver.Manage().Window.Size = new Size(480, 320);
5) Save and click on ‘Start’ button to execute the above code.
Observe that the Selenium C# Script will get executed and observe that the Chrome browser will be displayed in customized size as per above the x and y coordinate arguments (i.e. 480 ad 320) as shown below:
Here concludes this article.
In the next article, I will choose another Selenium command for performing different operation on the web page.
- > To learn more about Selenium C#, continue to the next post (Click on Next Post Link Below)
- > Check complete Selenium C# Tutorial Contents here (Click here)
Please leave your questions/comments/feedback below.
Happy Learning 🙂
On a mission to contribute to the Software Testing Community in all possible ways.