N NextGen Virtual Academy
AD Administrator Learning Manager
SELENIUM WEBDRIVER · PRACTICE LAB

Windows & Tabs

Practice handling parent windows, child windows, browser tabs and window switching using Selenium WebDriver.

LAB WINDOW
OBJECTIVE

What You Will Practice

  • Capture the parent window handle.
  • Get all available window handles.
  • Open and switch to a child window.
  • Work with multiple browser tabs.
  • Return to the parent window.
  • Close a child window safely.
01

Parent Window

Capture and identify the current browser window handle.

HANDLE
P
Parent Window Current browser window
Selenium Command String parentWindow = driver.getWindowHandle();
02

Open Child Window

Open a new browser window and identify the new window.

CHILD
P Parent
Selenium Practice driver.switchTo().newWindow(WindowType.WINDOW);
03

Multiple Windows

Create multiple browser windows and inspect their window handles.

MULTIPLE
Selenium Command Set<String> windows = driver.getWindowHandles();
04

Browser Tabs

Practice opening and identifying a new browser tab.

TABS
Tab 1
Selenium 4 Command driver.switchTo().newWindow(WindowType.TAB);
05

Switch Between Windows

Practice selecting a specific window from the available handles.

SWITCH
Current window: Parent
Selenium Command driver.switchTo().window(windowHandle);
06

Close Child & Return

Practice closing a child window and switching back to the parent.

CLOSE
1 Parent
2 Child
3 Parent
Selenium Flow driver.close(); driver.switchTo().window(parentWindow);
QUICK REFERENCE

Selenium Windows & Tabs Commands

Current Window
String parent =
    driver.getWindowHandle();
All Windows
Set<String> windows =
    driver.getWindowHandles();
Switch Window
driver.switchTo()
    .window(windowHandle);
New Window
driver.switchTo()
    .newWindow(WindowType.WINDOW);
New Tab
driver.switchTo()
    .newWindow(WindowType.TAB);
Close Current
driver.close();