Bird
0
0

Consider the following Selenium Java code snippet:

medium📝 Predict Output Q4 of 15
Selenium Java - Page Object Model
Consider the following Selenium Java code snippet:
driver.get("https://example.com/start");
driver.findElement(By.cssSelector("button.next")).click();
String pageTitle = driver.getTitle();
System.out.println(pageTitle);

If clicking the button navigates to a page titled "Example - Page 2", what will be printed?
A"Example - Page 2"
B"Example - Start"
C"https://example.com/start"
D"button.next"
Step-by-Step Solution
Solution:
  1. Step 1: Navigate to initial URL

    The driver opens "https://example.com/start".
  2. Step 2: Click the next button

    The click triggers navigation to the next page.
  3. Step 3: Get the page title

    driver.getTitle() returns the title of the current page, which is "Example - Page 2".
  4. Final Answer:

    "Example - Page 2" -> Option A
  5. Quick Check:

    Title reflects current page after navigation [OK]
Quick Trick: getTitle() returns current page title after navigation [OK]
Common Mistakes:
  • Assuming getTitle() returns previous page title
  • Confusing URL with page title
  • Not waiting for page load before getting title

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes