0
0
Selenium Javatesting~20 mins

First Selenium Java test - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Selenium Java Test 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 test?
Consider this Selenium Java test code snippet. What will be the test result after execution?
Selenium Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.Assert;
import org.junit.Test;

public class SimpleTest {
    @Test
    public void testTitle() {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        String title = driver.getTitle();
        Assert.assertEquals("Example Domain", title);
        driver.quit();
    }
}
ATest passes because the page title matches "Example Domain".
BTest fails because the driver is not closed properly.
CTest fails because the URL is incorrect.
DTest fails due to a NoSuchElementException.
Attempts:
2 left
💡 Hint
Think about what the getTitle() method returns for https://example.com.
locator
intermediate
1:30remaining
Which locator is best to find the login button?
Given a login button with HTML: , which locator is the best practice to find it in Selenium Java?
ABy.id("loginBtn")
BBy.className("btn")
CBy.xpath("//button[text()='Login']")
DBy.cssSelector("button[aria-label='Login']")
Attempts:
2 left
💡 Hint
Use the most specific and stable locator.
assertion
advanced
2:00remaining
Which assertion correctly verifies the presence of a success message?
You want to check if the element with id "successMsg" contains the text "Login successful". Which assertion is correct in Selenium Java with JUnit?
Selenium Java
WebElement message = driver.findElement(By.id("successMsg"));
String text = message.getText();
AAssert.assertEquals("Login successful", text);
BAssert.assertNotNull(text);
CAssert.assertTrue(text.contains("Login successful"));
DAssert.assertFalse(text.isEmpty());
Attempts:
2 left
💡 Hint
The message might contain extra spaces or other text.
🔧 Debug
advanced
2:30remaining
Why does this Selenium test throw NoSuchElementException?
This test fails with NoSuchElementException: WebDriver driver = new ChromeDriver(); driver.get("https://example.com/login"); WebElement input = driver.findElement(By.id("username")); input.sendKeys("user1"); What is the most likely cause?
AThe driver was not initialized before calling findElement.
BThe sendKeys method is called before findElement.
CThe URL is incorrect and page did not load.
DThe element with id "username" is inside an iframe and not switched to.
Attempts:
2 left
💡 Hint
Check if the element is inside a frame or iframe.
framework
expert
3:00remaining
What is the correct order of JUnit annotations for Selenium test lifecycle?
Arrange these JUnit annotations in the order they execute during a Selenium test run: 1. @BeforeClass 2. @Before 3. @Test 4. @After 5. @AfterClass
A2,1,3,4,5
B1,2,3,4,5
C1,3,2,4,5
D1,2,4,3,5
Attempts:
2 left
💡 Hint
Think about setup and teardown phases at class and test method levels.