How to Handle Multiple Windows/Tabs in Selenium? Firstly, We will open three different tabs with different URLs and store unique identifier strings returned by the getWindowHandle() method in tab1, tab2, and tab3 string variables. Next, we will switch to Tab 2 using the driver.switchTo().window() method. We will then use the getWindowHandles() method to get the window handles and store them […]

This tutorial will briefly discuss the difference between getWindowHandle() and getWindowHandles() with a sample project. getWindowHandle() returns the window handle of the current or active window. getWindowHandles() returns a set of window handles for all the windows opened by the WebDriver instance. Example: package TestAutomationCentral; import org.openqa.selenium.WebDriver;import org.openqa.selenium.WindowType;import org.openqa.selenium.chrome.ChromeDriver; import java.util.Set; public class SeleniumWindowHandles { public static void main(String[] args) […]