Bird
Raised Fist0
Selenium Javatesting~20 mins

Multi-page navigation flow in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Multi-page Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Selenium Java code snippet?
Consider the following Selenium Java code that navigates through two pages and checks the title of the second page. What will be printed to the console?
Selenium Java
WebDriver driver = new ChromeDriver();
driver.get("https://example.com/page1");
String title1 = driver.getTitle();
driver.findElement(By.id("nextPageLink")).click();
new WebDriverWait(driver, Duration.ofSeconds(5))
    .until(ExpectedConditions.titleContains("Page 2"));
String title2 = driver.getTitle();
System.out.println(title2);
driver.quit();
ATimeoutException
BPage 1 - Example Domain
CPage 2 - Example Domain
DNoSuchElementException
Attempts:
2 left
💡 Hint
Think about what happens after clicking the link and waiting for the new page title.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies the URL after navigation?
After clicking a link that navigates to "https://example.com/dashboard", which assertion correctly verifies the current URL in Selenium Java?
Selenium Java
driver.findElement(By.linkText("Dashboard")).click();
// Wait for navigation to complete
new WebDriverWait(driver, Duration.ofSeconds(5))
    .until(ExpectedConditions.urlToBe("https://example.com/dashboard"));
AassertNotNull(driver.getCurrentUrl());
BassertTrue(driver.getCurrentUrl().contains("dashboard"));
CassertFalse(driver.getCurrentUrl().equals("https://example.com/home"));
DassertEquals(driver.getCurrentUrl(), "https://example.com/dashboard");
Attempts:
2 left
💡 Hint
Check which assertion exactly matches the expected URL.
🔧 Debug
advanced
2:00remaining
Why does this multi-page navigation test fail intermittently?
This Selenium Java test clicks a link to navigate to a new page and then asserts the page title. Sometimes it fails with an AssertionError. What is the most likely cause?
Selenium Java
driver.findElement(By.id("profileLink")).click();
assertEquals(driver.getTitle(), "User Profile");
AThe locator By.id("profileLink") is incorrect and throws NoSuchElementException.
BThe test does not wait for the new page to load before checking the title.
CThe assertion syntax is wrong and causes a compilation error.
DThe driver.quit() is called before the assertion.
Attempts:
2 left
💡 Hint
Think about page load timing and synchronization.
❓ locator
advanced
2:00remaining
Which locator is best for clicking a 'Next' button in a multi-page flow?
You want to click the 'Next' button to go to the next page in a multi-page form. The button has the text 'Next' and a class 'btn-next'. Which locator is the best practice in Selenium Java?
ABy.cssSelector("button.btn-next")
BBy.className("btn-next")
CBy.xpath("//button[text()='Next']")
DBy.linkText("Next")
Attempts:
2 left
💡 Hint
Consider specificity and stability of locators.
❓ framework
expert
3:00remaining
How to design a robust multi-page navigation test framework in Selenium Java?
Which approach best supports maintainability and reliability for multi-page navigation tests in Selenium Java?
AUse Page Object Model with explicit waits and separate methods for navigation actions.
BWrite all navigation steps inline in test methods without abstraction.
CUse Thread.sleep() after each click to wait for page loads.
DAvoid waits and rely on implicit waits only.
Attempts:
2 left
💡 Hint
Think about code reuse, readability, and synchronization.

Practice

(1/5)
1. What is the main purpose of multi-page navigation testing in Selenium?
easy
A. To check database connections
B. To verify users can move through pages correctly
C. To test API responses
D. To validate CSS styles on a page

Solution

  1. Step 1: Understand multi-page navigation testing

    It focuses on checking if users can move from one page to another as expected.
  2. Step 2: Identify the correct purpose

    Among the options, only verifying page navigation matches this goal.
  3. Final Answer:

    To verify users can move through pages correctly -> Option B
  4. Quick Check:

    Multi-page navigation = verify page moves [OK]
Hint: Focus on user movement between pages [OK]
Common Mistakes:
  • Confusing navigation testing with API or database testing
  • Thinking CSS validation is part of navigation
  • Ignoring the user flow aspect
2. Which Selenium Java command is used to navigate to a new URL in a multi-page test?
easy
A. driver.get("https://example.com")
B. driver.click("https://example.com")
C. driver.navigateTo("https://example.com")
D. driver.openPage("https://example.com")

Solution

  1. Step 1: Recall Selenium command to open URL

    The correct method is driver.get(url) to load a page.
  2. Step 2: Check options for correct syntax

    Only driver.get("https://example.com") is valid Selenium Java syntax.
  3. Final Answer:

    driver.get("https://example.com") -> Option A
  4. Quick Check:

    Open URL = driver.get() [OK]
Hint: Use driver.get() to open URLs [OK]
Common Mistakes:
  • Using non-existent methods like navigateTo or openPage
  • Trying to click URLs directly
  • Confusing navigation commands with click actions
3. 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?
medium
A. "https://example.com/page1"
B. null
C. Throws NoSuchElementException
D. "https://example.com/page2"

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]
Hint: 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
4. Identify the error in this Selenium Java code for multi-page navigation:
driver.get("https://example.com/home");
WebElement link = driver.findElement(By.className("nav-link"));
link.click();
String title = driver.getTitle();
assert title.equals("Home Page");
medium
A. Missing driver.quit() after test
B. Incorrect assertion method syntax
C. Using className locator without checking multiple matches
D. Using getTitle() instead of getCurrentUrl()

Solution

  1. Step 1: Analyze locator usage

    Using By.className("nav-link") may find multiple elements, causing ambiguity.
  2. Step 2: Check other code parts

    Assertion syntax is correct, driver.quit() is optional, and getTitle() is valid for title check.
  3. Final Answer:

    Using className locator without checking multiple matches -> Option C
  4. Quick Check:

    className may match many elements [OK]
Hint: Ensure locators uniquely identify elements [OK]
Common Mistakes:
  • Ignoring that className can match multiple elements
  • Thinking getTitle() is wrong for title checks
  • Believing driver.quit() is mandatory in every snippet
5. You want to test a multi-page flow where after login, the user clicks a menu to open a settings page, then clicks a logout button. Which Selenium Java approach correctly verifies the flow?
hard
A. Use driver.get() for login page, findElement().sendKeys() for login, click menu link, verify settings URL, click logout, verify login URL
B. Use driver.navigate().refresh() after each click to ensure page loads
C. Use driver.get() only once at login, then use JavaScript to change URLs for other pages
D. Use driver.findElement(By.tagName("button")).click() for all clicks without verifying page changes

Solution

  1. Step 1: Outline correct multi-page test steps

    Start at login page, perform login, navigate via clicks, verify URLs after each step.
  2. Step 2: Evaluate options for best practice

    Use driver.get() for login page, findElement().sendKeys() for login, click menu link, verify settings URL, click logout, verify login URL follows proper navigation and verification. Others misuse refresh, JavaScript URL changes, or skip verification.
  3. Final Answer:

    Use driver.get() for login page, findElement().sendKeys() for login, click menu link, verify settings URL, click logout, verify login URL -> Option A
  4. Quick Check:

    Navigate and verify URLs step-by-step [OK]
Hint: Navigate and verify each page URL after clicks [OK]
Common Mistakes:
  • Refreshing unnecessarily after clicks
  • Changing URLs via JavaScript instead of real navigation
  • Clicking without verifying page changes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard