Challenge - 5 Problems
Advanced Selenium Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Java test snippet?
Consider the following Selenium Java code that tries to find a button and click it. What will be the output if the button is not present on the page?
Selenium Java
WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); try { WebElement button = driver.findElement(By.id("submitBtn")); button.click(); System.out.println("Clicked the button."); } catch (NoSuchElementException e) { System.out.println("Button not found."); } driver.quit();
Attempts:
2 left
💡 Hint
Think about what happens when findElement does not find the element and how the exception is handled.
✗ Incorrect
The code catches NoSuchElementException and prints "Button not found." instead of letting the exception crash the test.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the page title in Selenium Java?
You want to verify that the page title is exactly "Welcome Page" after navigation. Which assertion is correct?
Selenium Java
String expectedTitle = "Welcome Page";
String actualTitle = driver.getTitle();Attempts:
2 left
💡 Hint
Exact match requires equality assertion.
✗ Incorrect
assertEquals checks that actualTitle exactly matches expectedTitle, which is needed here.
❓ locator
advanced2:00remaining
Which locator is best to find a button with dynamic ID but fixed visible text "Submit"?
The button's ID changes every page load, but the button always shows the text "Submit". Which locator is most reliable?
Attempts:
2 left
💡 Hint
Use visible text when IDs are dynamic.
✗ Incorrect
XPath with exact text match is reliable when IDs change but text is fixed.
🔧 Debug
advanced2:30remaining
Why does this Selenium Java test intermittently fail with StaleElementReferenceException?
Code snippet:
WebElement menu = driver.findElement(By.id("menu"));
menu.click();
WebElement submenu = driver.findElement(By.id("submenu"));
submenu.click();
Sometimes the test fails on submenu.click() with StaleElementReferenceException. Why?
Attempts:
2 left
💡 Hint
Think about page updates after clicking menu.
✗ Incorrect
Clicking menu reloads or updates the submenu element, invalidating the old reference causing the exception.
❓ framework
expert3:00remaining
In a Selenium Java test framework, which design pattern best supports maintainability and reusability for complex UI tests?
You are building a large test suite for a web app with many pages and complex interactions. Which design pattern is best to organize your Selenium tests?
Attempts:
2 left
💡 Hint
Think about separating page structure from test logic.
✗ Incorrect
Page Object Model organizes UI elements and actions per page, improving maintainability and reuse.