Implementation:SeleniumHQ Selenium WindowType
| 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
TABwhen you want to open a new page in the same browser window (common for multi-tab testing). - Use
WINDOWwhen you need a completely new browser window (useful for testing multi-window workflows or pop-up scenarios).
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/WindowType.java
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
| Constant | Wire Value | Description |
|---|---|---|
WINDOW |
"window" |
Open a new top-level browser window |
TAB |
"tab" |
Open a new tab in an existing browser window |
| 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
- Implementation:SeleniumHQ_Selenium_PageLoadStrategy -- another W3C capability enum
- Implementation:SeleniumHQ_Selenium_WebDriverException -- base exception for WebDriver errors
- Concept:W3C_WebDriver_Window_Management -- the window management model where WindowType is used