Complete the code to get all window handles.
Set<String> handles = driver.[1]();The method getWindowHandles() returns a set of all window handles opened by the WebDriver.
Complete the code to switch to a new window handle.
for (String handle : driver.[1]()) { driver.switchTo().window(handle); }
We use getWindowHandles() to get all window handles and then switch to each one.
Fix the error in the code to correctly get window handles.
Set<String> handles = driver.[1];The method getWindowHandles() must be called with parentheses to invoke it.
Fill both blanks to iterate over window handles and print each handle.
for ([1] handle : driver.[2]()) { System.out.println(handle); }
The variable type for window handles is String, and the method to get all handles is getWindowHandles().
Fill all three blanks to switch to a new window and close it.
Set<String> handles = driver.[1](); for ([2] handle : handles) { if (!handle.equals(driver.[3]())) { driver.switchTo().window(handle); driver.close(); } }
We get all window handles with getWindowHandles(), iterate with String type, and compare with the current window handle from getWindowHandle().