Complete the code to switch to the current browser window.
driver.switchTo().window([1]);The getWindowHandle() method returns the current window handle, which is used to switch to a specific window.
Complete the code to get all window handles after opening a new tab.
Set<String> windowHandles = driver.[1]();The getWindowHandles() method returns a set of all open window handles, which is useful to switch between multiple windows.
Fix the error in the code to switch to the second window handle.
for (String handle : driver.getWindowHandles()) { if (!handle.equals([1])) { driver.switchTo().window(handle); break; } }
The code compares each handle to the current window handle, which is obtained by driver.getWindowHandle(). This ensures switching to a different window.
Fill both blanks to correctly switch back to the original window after closing the new one.
String originalWindow = driver.[1](); // After closing new window driver.switchTo().[2](originalWindow);
The first blank uses getWindowHandle() to save the original window handle. The second blank uses window to switch back to that window.
Fill all three blanks to create a map of window titles keyed by their handles.
Map<String, String> windowTitles = new HashMap<>(); for (String handle : driver.[1]()) { driver.switchTo().[2](handle); windowTitles.put(handle, driver.[3]()); }
The code loops through all window handles (getWindowHandles()), switches to each window (window()), and stores the window title (getTitle()) in a map.