Bird
0
0

Given the code snippet:

medium📝 Predict Output Q13 of 15
Selenium Java - Page Object Model
Given the code snippet:
driver.get("https://example.com/page1");
driver.findElement(By.id("nextBtn")).click();
String currentUrl = driver.getCurrentUrl();

What will currentUrl contain after execution if clicking the button navigates to page2?
A"https://example.com/page1"
Bnull
CThrows NoSuchElementException
D"https://example.com/page2"
Step-by-Step Solution
Solution:
  1. Step 1: Understand navigation flow in code

    The driver opens page1, then clicks a button that navigates to page2.
  2. Step 2: Check what getCurrentUrl() returns after navigation

    It returns the URL of the current page, which should be page2 after clicking.
  3. Final Answer:

    "https://example.com/page2" -> Option D
  4. Quick Check:

    After click, URL updates to new page [OK]
Quick Trick: getCurrentUrl() shows current page URL [OK]
Common Mistakes:
  • Assuming URL stays the same after navigation
  • Confusing getCurrentUrl() with getPageSource()
  • Thinking click throws exception without checking element presence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes