Bird
0
0

You want to open a new tab, navigate to "https://selenium.dev", then switch back to the original tab and verify its title. Which code sequence correctly achieves this in Selenium Java?

hard📝 Application Q8 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You want to open a new tab, navigate to "https://selenium.dev", then switch back to the original tab and verify its title. Which code sequence correctly achieves this in Selenium Java?
Adriver.get("https://selenium.dev"); driver.switchTo().newWindow(WindowType.TAB); driver.switchTo().window(original); System.out.println(driver.getTitle());
Bdriver.switchTo().newWindow(WindowType.TAB); driver.get("https://selenium.dev"); driver.switchTo().window(original); System.out.println(driver.getTitle());
CString original = driver.getWindowHandle(); driver.get("https://selenium.dev"); driver.switchTo().newWindow(WindowType.TAB); System.out.println(driver.getTitle());
DString original = driver.getWindowHandle(); WebDriver newTab = driver.switchTo().newWindow(WindowType.TAB); newTab.get("https://selenium.dev"); driver.switchTo().window(original); System.out.println(driver.getTitle());
Step-by-Step Solution
Solution:
  1. Step 1: Store original window handle

    Save the current window handle before opening a new tab.
  2. Step 2: Open new tab and navigate

    Use switchTo().newWindow(WindowType.TAB) and navigate to the desired URL.
  3. Step 3: Switch back to original tab

    Use switchTo().window(original) to return focus.
  4. Step 4: Verify title

    Call getTitle() on driver to get the original tab's title.
  5. Final Answer:

    String original = driver.getWindowHandle(); WebDriver newTab = driver.switchTo().newWindow(WindowType.TAB); newTab.get("https://selenium.dev"); driver.switchTo().window(original); System.out.println(driver.getTitle()); correctly follows these steps.
  6. Quick Check:

    Save handle, open tab, switch back, verify [OK]
Quick Trick: Save handle first, then open tab, switch back, verify [OK]
Common Mistakes:
  • Not saving original handle before opening new tab
  • Navigating before opening new tab
  • Switching windows in wrong order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes