Complete the code to open a new browser tab using Selenium WebDriver.
driver.switchTo().newWindow([1]);Use WindowType.TAB to open a new tab in Selenium WebDriver.
Complete the code to switch the WebDriver context to the newly opened tab.
String newTabHandle = driver.getWindowHandles().toArray()[[1]].toString();
driver.switchTo().window(newTabHandle);The new tab is usually the second window handle, at index 1.
Fix the error in the code to correctly open a new window instead of a tab.
driver.switchTo().newWindow([1]);Use WindowType.WINDOW to open a new browser window.
Fill both blanks to open a new tab and navigate to a URL.
driver.switchTo().newWindow([1]); driver.get([2]);
Open a new tab with WindowType.TAB and navigate to "https://selenium.dev".
Fill all three blanks to open a new window, switch to it, and verify the title.
driver.switchTo().newWindow([1]); String newHandle = driver.getWindowHandles().toArray()[[2]].toString(); driver.switchTo().window(newHandle); assertEquals([3], driver.getTitle());
Open a new window with WindowType.WINDOW, switch to the second handle at index 1, and assert the title matches "New Window Title".
