Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium WindowType

From Leeroopedia
Knowledge Sources
Domains WebDriver, Browser_Automation
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for specifying the type of new browser window to create, provided by the Selenium WebDriver library.

Description

WindowType is a Java enum in the org.openqa.selenium package that represents the type of new browser window that may be created via the W3C WebDriver "New Window" command. As documented in the source Javadoc: "Represents the type of new browser window that may be created."

The enum defines two constants:

  • WINDOW ("window") -- Create a new top-level browser window.
  • TAB ("tab") -- Create a new browser tab within an existing window.

Each enum constant wraps a lowercase string corresponding to the W3C wire protocol value. The enum provides a case-insensitive fromString static factory method for deserialization and overrides toString() to return the wire-protocol string.

Usage

Use WindowType with the WebDriver.TargetLocator.newWindow(WindowType) method to open either a new tab or a new window:

  • Use TAB when you want to open a new page in the same browser window (common for multi-tab testing).
  • Use WINDOW when you need a completely new browser window (useful for testing multi-window workflows or pop-up scenarios).

Code Reference

Source Location

Signature

public enum WindowType {
    WINDOW("window"),
    TAB("tab");

    WindowType(String text)
    public String toString()
    public static WindowType fromString(String text)
}

Import

import org.openqa.selenium.WindowType;

I/O Contract

Enum Constants
Constant Wire Value Description
WINDOW "window" Open a new top-level browser window
TAB "tab" Open a new tab in an existing browser window
Methods
Method Input Output Description
toString() none String -- wire-protocol value Returns the lowercase string representation of the window type
fromString(String text) String (nullable, case-insensitive) WindowType or null Looks up the enum constant matching the given string; returns null if no match or input is null

Usage Examples

// Open a new tab and switch to it
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
driver.switchTo().newWindow(WindowType.TAB);
driver.get("https://example.com/other-page");

// Open a new window and switch to it
driver.switchTo().newWindow(WindowType.WINDOW);
driver.get("https://example.com/popup");

// Convert from a string value
WindowType type = WindowType.fromString("tab"); // returns WindowType.TAB

// Get the wire-protocol string
String wireValue = WindowType.WINDOW.toString(); // returns "window"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment