Bird
0
0

Consider this code snippet:

medium📝 Predict Output Q5 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Consider this code snippet:
driver.get("https://example.com");
String mainWindow = driver.getWindowHandle();
WebDriver newTab = driver.switchTo().newWindow(WindowType.TAB);
newTab.get("https://selenium.dev");
System.out.println(driver.getCurrentUrl());
What URL will be printed?
ARuntime error
Bhttps://selenium.dev
Cnull
Dhttps://example.com
Step-by-Step Solution
Solution:
  1. Step 1: Understand driver focus after new tab

    After newWindow(WindowType.TAB), driver focus switches to the new tab.
  2. Step 2: Check URL after navigation

    The new tab navigates to https://selenium.dev, so driver.getCurrentUrl() returns this URL.
  3. Final Answer:

    https://selenium.dev -> Option B
  4. Quick Check:

    Current URL = new tab URL [OK]
Quick Trick: Driver focus moves to new tab automatically [OK]
Common Mistakes:
MISTAKES
  • Expecting URL of original tab
  • Confusing driver and newTab references
  • Assuming driver stays on old tab

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes