Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a new browser tab using Selenium WebDriver.
Selenium Java
driver.switchTo().newWindow([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WindowType.WINDOW opens a new window, not a tab.
Using WindowType.FRAME or WindowType.POPUP are invalid for this method.
✗ Incorrect
Use WindowType.TAB to open a new tab in Selenium WebDriver.
2fill in blank
mediumComplete the code to switch the WebDriver context to the newly opened tab.
Selenium Java
String newTabHandle = driver.getWindowHandles().toArray()[[1]].toString();
driver.switchTo().window(newTabHandle); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 switches back to the original window.
Using negative or out-of-range indices causes errors.
✗ Incorrect
The new tab is usually the second window handle, at index 1.
3fill in blank
hardFix the error in the code to correctly open a new window instead of a tab.
Selenium Java
driver.switchTo().newWindow([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WindowType.TAB opens a new tab, not a window.
WindowType.POPUP and WindowType.FRAME are invalid here.
✗ Incorrect
Use WindowType.WINDOW to open a new browser window.
4fill in blank
hardFill both blanks to open a new tab and navigate to a URL.
Selenium Java
driver.switchTo().newWindow([1]); driver.get([2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WindowType.WINDOW opens a new window, not a tab.
Passing a variable instead of a string URL causes errors.
✗ Incorrect
Open a new tab with WindowType.TAB and navigate to "https://selenium.dev".
5fill in blank
hardFill all three blanks to open a new window, switch to it, and verify the title.
Selenium Java
driver.switchTo().newWindow([1]); String newHandle = driver.getWindowHandles().toArray()[[2]].toString(); driver.switchTo().window(newHandle); assertEquals([3], driver.getTitle());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WindowType.TAB opens a tab, not a window.
Using wrong index for window handles causes switching errors.
Passing a variable instead of a string literal to assertEquals.
✗ Incorrect
Open a new window with WindowType.WINDOW, switch to the second handle at index 1, and assert the title matches "New Window Title".