Home » Software Testing » Automation Testing » Selenium WebDriver Tutorial » Maximize Browser Window Using Selenium WebDriver And By Using Abstract Window Toolkit

Maximize Browser Window Using Selenium WebDriver And By Using Abstract Window Toolkit

Maximizing window in Selenium WebDriver is really quite easy but sometimes you find it really hard to maximize the window while using Selenium Grid.

Many time you get stuck to such a scenario where scripts start failing on remote machine because your previously written code does not work. The reason could be anything, Might be

1- Your browser on the remote machine could possibly be updated and still you are using old Selenium Standalone jar
2- Might be your code is unable to maximize your browser instance. Due to this few of the WebElement seems eclipsed due to the size of the browser window.

So let’s see how you can maximize your browser window using Selenium WebDriver along with Abstract Window Toolkit. here is the list of few methods that can help you to get the requisite result.
maximize browser in Selenium WebDriver

1- Using the traditional way to Selenium WebDriver maximize() method
So why not we are going to write one script then:
Step 1: Create one class name MaximizeBrowser but before that would suggest adding Selenium Standalone jar in classpath. To read how to do this read Downloading and Configuring Selenium Webdriver in Eclipse with TestNG plugin installation.
Step 2: Copy and past complete code and replace everything in MaximizeBrowser class except package

If you want to experiment with Chrome Browser then follow Launching Chrome Browser using WebDriver.

2- This option was totally for Chrome browser and in this script, we were using Chrome Option to maximize chrome browser (Still looking to perform this action with DesiredCapability for IE and Firefox)

So again let’s see one more example but this time we are going to take the example of Chrome Browser.
1- Create one class MaximizeChromeBrowser
2- Copy and paste the following code and replace everything except package in MaximizeChromeBrowser  class

So by using the above code we can maximize chrome browser but be assured that the above code is not going to work on IE and Firefox browser. So why not we move to one more method like this because this is going to work across the browser.

3- By using Toolkit utility, we can maximize the browser window as per the resolution of your computer screen resolution. So let’s see one more example.
Step 1: Create one class MaximizeBrowser
Step 2: Copy and paste the following code and replace everything except package in your class and run it

4- All the above code can help you to maximize browser, But what if you need to run your test script in a custom size of the browser then might be this code would help you a lot.

So if you are putting Width =300 and Height=600 then your browser size will be turned in the same size.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.