Selenium-8: Windows


In this post we will learn how to work with windows/tabs while we are doing web automation with selenium webdriver.


This post is designed for SW test professionals who have some information about selenium web automation. At the end of this tutorial, you will know how to work with windows/tabs.


Nice to have: Before starting to read this post it is better to read previous selenium tutorials.

Working with Window Handles

Every window has a unique handle. Handle means a specific identifier that represents its window. We can manage the windows with their handles. I want to explain what Selenium Webdriver provides us for window handles.

– driver.getWindowHandle() – We can get current window’s handle

– driver.getWindowHandles() – We can get all windows handles

– driver.switchTo().window(String handle) – We can switch to the target window by using its handle.

Example-1: Window Handles

Test website:

Test Scenario:

  1. Go to above URL.
  2. Get the current window’s handle and write to the console window. It must be first window handle.
  3. Locate the “Visit!” link and click it.
  4. Get all window handles and hold them in a list.
  5. Write to total window handle number to the console. It must be 2.
  6. Switch to second window.
  7. Get the current window’s handle and write to the console window. It must be second window handle.
  8. Check the upper left side text is “THE WORLD’S LARGEST WEB DEVELOPER SITE” in second window.
  9. Go back (Switch) to first window.
  10. Get the current window’s handle and write to the console window. It must be first window handle.
  11. Check the See Result Button Text. It must contain “See Result” text.

Test Code:

Console Output:


How to Manage Windows

Webdriver provides us below methods to manage windows. We can control the size and position of the current window with the following methods.


– .maximize() – It maximizes the current window.

– .getSize() – It returns the size of the current window.

– .setSize() – It sets a new size to current window.

– .getPosition() – It returns current position in term of x,y coordinates.

– .setPosition() – It moves the current window around.

Example-2: Manage Window

Test website:

Test Scenario:

  1. Navigate to above URL.
  2. Maximize the current window.
  3. Get size of the window and write the full screen size to the console.
  4. Minimize the window by 1/4 and write the new screen size to the console.
  5. Get window position and write it to the console.
  6. Set window position x=100 and y=200 and write to the console.

Test Code:

Console Output:



  • You learnt how to handle and manage browser windows with selenium webdriver methods.


Database Operations in JavaFX

By Onur Baskirt / Apr 1, 2016 / 56 Comments
Before started this section, please check the first article and learn How to Start JAVAFX! At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an...
rest assured

REST API Testing with Rest Assured

By Onur Baskirt / Mar 8, 2016 / 32 Comments
Outline In this post, I will explain what is API and API testing, what is the difference between SOAP and REST services, and how to test REST APIs with Rest Assured Library. What is API? API stands for Application Programming...

How to Write Effective CSS Locators

By Onur Baskirt / Oct 1, 2017 / 0 Comments
Hi all, in this tutorial, I will describe you how to write effective CSS locators to interrogate web elements for your automation projects. As a rule of thumb, your interrogation strategy should be in below order: First try to use...

Selenium-11: Execute JavaScript with JavascriptExecutor

By Onur Baskirt / Jan 27, 2016 / 15 Comments
Outline Sometimes we cannot handle some conditions or problems with Webdriver, web controls don't react well against selenium commands. In this kind of situations, we use Javascript. It is useful for custom synchronizations, hide or show the web elements, change...

Getting Started with JavaFX

By Onur Baskirt / Mar 25, 2016 / 0 Comments
When I started to work in my current position, one of my task is to do manual operations for campaign products  every week. After the second week, I thought that I have to automate this task using a GUI based...

How to Write Smart XPath Locators

By Onur Baskirt / Sep 24, 2017 / 4 Comments
Hi all, in this tutorial, I will describe you how to write smart and non-brittle XPath locators. When we write our test scripts, we generally prefer to use id, name, class, etc. these kinds of locators. However, sometimes we could not...

Selenium-1: Quick Start to Automation with Selenium WebDriver & JAVA & JUnit & Maven & IntelliJ

By Onur Baskirt / Sep 8, 2015 / 26 Comments
Outline Selenium Webdriver is the most popular open source web test automation framework across wide range of browsers and platforms. In this tutorial you will learn how to do web test automation with Selenium Webdriver and the related tools. Audience...
page object model

Page Object Model with C#

By Ege Aksoz / Jun 18, 2017 / 8 Comments
In the previous tutorial, we’ve taken the initial steps and entered the world of automated testing. We also wrote our first automated test. From this point on, since we are not just going to write one test, we need to...

How to Select a Date From DatePicker Using Selenium

By Onur Baskirt / Aug 13, 2016 / 6 Comments
When you need to automate a airway, hotel, or similar websites you need to deal with Datepickers and some times it is a little bit cumbersome to select a specific date on the Datepicker or calendar.  In this post, I...

Selenium Webdriver Performance testing with Jmeter and Selenium Grid

By Ozgur Kaya / Aug 9, 2016 / 2 Comments
In this post, we will complete Selenium Webdriver Performance testing scenario using Jmeter and Selenium Grid. 1- Install Java 7 or later If necessary 2- Download latest Jmeter version 3.0 or higher. 3- Download Jmeter PluginsManager JAR file and...
By | 2017-01-13T21:33:46+00:00 December 29th, 2015|Selenium, Test Automation, Web Automation|1 Comment

About the Author:

Onur Baskirt
Onur Baskirt is a senior IT professional with 10+ years of experience. He worked at Bahçesehir University, ST Microelectronics, Huawei and Ericsson as research assistant, design verification engineer and software test leader. Also, he worked as software test leader and software operations manager at Turkey's biggest technology retailer, Teknosa. Now, he is working as Head of Software Testing and Manager of two Development Teams at His current research areas are technical software testing, programming, and computer science. Formerly, he has several research works and papers on digital chip design & verification. His hobbies are sport, dancing, traveling, and nutrition. You can find detailed information about him on his linked-in page.

One Comment

  1. Onur Baskirt
    Onur Baskirt January 4, 2016 at 12:25 am - Reply

    Thank you so much for your comments. I tried to open our site with IE11. I did not see any problem. Which version of IE you are using? I will try to test the site on that version.

Leave A Comment