0
0
Selenium Javatesting~20 mins

WebDriver setup (ChromeDriver) in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ChromeDriver Mastery
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 WebDriver setup code?
Consider the following Java code snippet for setting up ChromeDriver. What will be the result when this code runs?
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestSetup {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        System.out.println(driver.getTitle());
        driver.quit();
    }
}
APrints the title of https://example.com and closes the browser without errors
BThrows IllegalStateException because the driver path is not set correctly
CThrows NullPointerException when calling getTitle()
DPrints an empty string and leaves the browser open
Attempts:
2 left
💡 Hint
Check if the driver path is set and the driver instance is created properly.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the page title after ChromeDriver navigation?
You want to check that after navigating to "https://example.com", the page title is exactly "Example Domain". Which assertion is correct in Java with JUnit?
Selenium Java
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
// Which assertion below is correct?
AassertTrue(driver.getTitle() == "Example Domain");
BassertNull(driver.getTitle());
CassertFalse(driver.getTitle().equals("Example Domain"));
DassertEquals("Example Domain", driver.getTitle());
Attempts:
2 left
💡 Hint
Use the proper method to compare strings in Java assertions.
locator
advanced
1:30remaining
Which locator strategy is best for finding a button with id 'submitBtn' in Selenium?
You want to locate a button element with the id attribute 'submitBtn'. Which locator is the best practice in Selenium WebDriver Java?
Adriver.findElement(By.cssSelector("button#submitBtn"));
Bdriver.findElement(By.xpath("//button[@id='submitBtn']"));
Cdriver.findElement(By.id("submitBtn"));
Ddriver.findElement(By.name("submitBtn"));
Attempts:
2 left
💡 Hint
Id is unique and fastest locator.
🔧 Debug
advanced
2:00remaining
Why does this ChromeDriver setup code throw an exception?
Review the code below. It throws an IllegalStateException at runtime. What is the cause?
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Test {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        driver.quit();
    }
}
AChromeDriver constructor is deprecated and cannot be used directly
BSystem property 'webdriver.chrome.driver' is not set with the path to chromedriver executable
Cdriver.get() is called before driver initialization
Ddriver.quit() is called before driver.get()
Attempts:
2 left
💡 Hint
Check if the driver executable path is configured before creating ChromeDriver.
framework
expert
2:30remaining
Which setup method correctly initializes ChromeDriver for parallel test execution in JUnit 5?
You want to run Selenium tests in parallel using JUnit 5. Which setup method ensures each test gets its own ChromeDriver instance safely?
A
@BeforeEach
void setup() {
    System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
    driver = new ChromeDriver();
}
B
@BeforeAll
static void setup() {
    System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
    driver = new ChromeDriver();
}
C
@BeforeEach
void setup() {
    driver = new ChromeDriver();
}
D
@BeforeAll
static void setup() {
    driver = new ChromeDriver();
}
Attempts:
2 left
💡 Hint
Each test needs its own driver instance to avoid conflicts in parallel runs.