Maximize Window Using Selenium WebDriver And By Using Abstract Window Toolkit

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

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

1- Your browser on 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 browser window.

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

1- Using 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 to add Selenium Standalone jar in class path. 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 every thing 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 lets see one more example but this time we are going to take example of Chrome Browser.
1- Create one class MaximizeChromeBrowser
2- Copy and past following code and replace everything except package in MaximizeChromeBrowser  class

So by using above code we can maximize chrome browser but above can’t work for IE and Firefox browser. So why not we move to one more method like

that can work for all browser

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

4- Above all methods can help to maximize browser, But what if you need to run your test script in a custom size of 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.

Read Similar Posts

Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.

Leave a Reply

Your email address will not be published. Required fields are marked *