Switch to a new window and back
intermediate Windows and tabs Challenge 9 of 13
On the sign-up page, the Terms of Service link opens in a new window. The test needs to check the terms page heading, then return to the sign-up form and tick “I accept”.
Requirements
- Save the original window handle with
getWindowHandle()before clicking the link. - Find the new window with
getWindowHandles()and switch to it withswitchTo().window(...). Wait for it to open rather than sleeping. - Assert the
h1text on the terms page. - Close the terms window with
driver.close()and switch back to the original window before clicking#accept-terms.
Expected output
The test saves the sign-up window handle, waits for two windows, switches to the handle that is not the original, asserts the heading, closes that window and switches back before ticking the checkbox.
Checks (5)
- ○Saves the original window handle
- ○Finds the new window with getWindowHandles()
- ○Switches windows with switchTo().window()
- ○Closes the new window and switches back
- ○No Thread.sleep
Solution.javaValidated · not executed
Ctrl/⌘ + Enter to validate · your code is saved in this browser
Results
Validate your code against the checks.