Challenge - 5 Problems
Page Title & URL Master
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 code snippet?
Consider the following Selenium WebDriver code that opens a webpage and retrieves its title and URL. What will be printed to the console?
Selenium Java
WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); String title = driver.getTitle(); String url = driver.getCurrentUrl(); System.out.println(title + " - " + url); driver.quit();
Attempts:
2 left
💡 Hint
Remember that getTitle() returns the page title and getCurrentUrl() returns the current URL loaded in the browser.
✗ Incorrect
The code navigates to https://example.com, whose page title is "Example Domain". The getTitle() method returns this title, and getCurrentUrl() returns the URL. The output concatenates these with " - ".
❓ 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 loading the page. Which assertion is correct?
Selenium Java
WebDriver driver = new ChromeDriver();
driver.get("https://mysite.com/welcome");
String actualTitle = driver.getTitle();Attempts:
2 left
💡 Hint
You want to check exact equality, not just presence or non-null.
✗ Incorrect
assertEquals(expected, actual) checks that the actual title exactly matches "Welcome Page". Other options check partial or non-null conditions but do not verify exact match.
❓ locator
advanced1:30remaining
Identify the best locator to verify the current URL contains a specific path
You want to write a test that verifies the current URL contains the path "/dashboard" after login. Which Selenium Java code snippet correctly retrieves the URL for this check?
Attempts:
2 left
💡 Hint
The URL is not an element on the page but a property of the browser.
✗ Incorrect
getCurrentUrl() returns the current page URL loaded in the browser. Using findElement or getTitle does not retrieve the URL. getPageSource returns HTML source, not URL.
🔧 Debug
advanced2:00remaining
Why does this Selenium Java test fail to get the page title?
Examine the code below. The test throws a NullPointerException when trying to get the title. What is the most likely cause?
Selenium Java
WebDriver driver;
driver.get("https://example.com");
String title = driver.getTitle();
System.out.println(title);Attempts:
2 left
💡 Hint
Check if the WebDriver object is assigned before use.
✗ Incorrect
The driver variable is declared but never assigned a new browser instance like new ChromeDriver(). Calling methods on a null driver causes NullPointerException.
❓ framework
expert2:30remaining
In a Selenium Java test framework, which method is best to retrieve and log page title and URL after each test?
You want to automatically log the page title and URL after every test method runs in your Selenium Java test suite using TestNG. Which approach is best?
Attempts:
2 left
💡 Hint
Think about running code after each test method automatically.
✗ Incorrect
@AfterMethod runs after each @Test method, making it ideal to retrieve and log page title and URL after every test. Calling inside each test is repetitive. @BeforeClass runs once before all tests. Static block runs once when class loads.