0
0
Selenium Javatesting~10 mins

Creating new windows/tabs in Selenium Java - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AWindowType.POPUP
BWindowType.WINDOW
CWindowType.TAB
DWindowType.FRAME
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.
2fill in blank
medium

Complete 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'
A1
B0
C2
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 switches back to the original window.
Using negative or out-of-range indices causes errors.
3fill in blank
hard

Fix 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'
AWindowType.WINDOW
BWindowType.FRAME
CWindowType.TAB
DWindowType.POPUP
Attempts:
3 left
💡 Hint
Common Mistakes
Using WindowType.TAB opens a new tab, not a window.
WindowType.POPUP and WindowType.FRAME are invalid here.
4fill in blank
hard

Fill 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'
AWindowType.TAB
B"https://example.com"
C"https://selenium.dev"
DWindowType.WINDOW
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.
5fill in blank
hard

Fill 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'
AWindowType.WINDOW
B1
C"New Window Title"
DWindowType.TAB
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.