Bird
Raised Fist0
Selenium Javatesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of setting up ChromeDriver in Selenium WebDriver tests?
easy
A. To control the Chrome browser automatically during tests
B. To write test cases in Java
C. To create HTML reports for test results
D. To manage database connections

Solution

  1. Step 1: Understand WebDriver role

    WebDriver controls browsers to simulate user actions in tests.
  2. Step 2: Identify ChromeDriver's function

    ChromeDriver is the specific driver that controls the Chrome browser.
  3. Final Answer:

    To control the Chrome browser automatically during tests -> Option A
  4. Quick Check:

    ChromeDriver controls Chrome browser [OK]
Hint: ChromeDriver lets Selenium talk to Chrome browser [OK]
Common Mistakes:
  • Confusing ChromeDriver with test case writing
  • Thinking ChromeDriver creates reports
  • Mixing browser control with database tasks
2. Which of the following is the correct way to set the ChromeDriver path in Java before creating a ChromeDriver instance?
easy
A. System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe");
B. ChromeDriver.setPath("path/to/chromedriver.exe");
C. WebDriver.chromeDriverPath = "path/to/chromedriver.exe";
D. driver.setChromeDriver("path/to/chromedriver.exe");

Solution

  1. Step 1: Recall Java system property syntax

    Setting ChromeDriver path uses System.setProperty with key "webdriver.chrome.driver".
  2. Step 2: Match correct method and parameters

    System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe"); correctly uses System.setProperty with the driver path string.
  3. Final Answer:

    System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe"); -> Option A
  4. Quick Check:

    Use System.setProperty for driver path [OK]
Hint: Use System.setProperty with key "webdriver.chrome.driver" [OK]
Common Mistakes:
  • Using non-existent methods like setPath or setChromeDriver
  • Assigning path directly to WebDriver variable
  • Missing quotes or wrong method names
3. What will happen if you run the following Java Selenium code snippet?
System.setProperty("webdriver.chrome.driver", "/drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
driver.quit();
medium
A. The browser opens but does not navigate to example.com
B. The code throws a syntax error at System.setProperty
C. The Chrome browser opens example.com and then closes
D. The ChromeDriver fails to start due to missing driver path

Solution

  1. Step 1: Analyze driver setup and navigation

    System.setProperty sets the driver path correctly, ChromeDriver instance is created, and driver.get opens the URL.
  2. Step 2: Check browser closing command

    driver.quit() closes the browser after navigation.
  3. Final Answer:

    The Chrome browser opens example.com and then closes -> Option C
  4. Quick Check:

    Correct setup opens and closes browser [OK]
Hint: Correct setup opens URL then quits browser [OK]
Common Mistakes:
  • Assuming syntax error without checking code
  • Thinking driver.get does not open URL
  • Forgetting driver.quit closes browser
4. Identify the error in this Selenium WebDriver setup code snippet:
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "/drivers/chromedriver");
driver.get("https://example.com");
medium
A. driver.get() should be called before setting system property
B. System.setProperty must be called before creating ChromeDriver instance
C. ChromeDriver path should be set using driver.setPath()
D. No error, code will run fine

Solution

  1. Step 1: Check order of setting driver path

    System.setProperty must be called before creating ChromeDriver to locate the driver executable.
  2. Step 2: Identify consequence of wrong order

    Creating ChromeDriver before setting path causes runtime error as driver is not found.
  3. Final Answer:

    System.setProperty must be called before creating ChromeDriver instance -> Option B
  4. Quick Check:

    Set driver path before ChromeDriver creation [OK]
Hint: Always set driver path before new ChromeDriver() [OK]
Common Mistakes:
  • Calling driver.get before setting driver path
  • Using non-existent driver.setPath method
  • Ignoring order of setup steps
5. You want to run multiple Selenium tests in parallel using ChromeDriver. Which setup practice helps avoid conflicts and resource leaks?
hard
A. Manually kill Chrome processes after all tests finish instead of driver.quit()
B. Use a single ChromeDriver instance shared by all tests without quitting
C. Set the ChromeDriver path only once at the start of all tests and never again
D. Create a new ChromeDriver instance for each test and call driver.quit() after each test

Solution

  1. Step 1: Understand parallel test isolation

    Each test should have its own ChromeDriver instance to avoid interference.
  2. Step 2: Importance of quitting driver

    Calling driver.quit() after each test frees resources and closes browser properly.
  3. Final Answer:

    Create a new ChromeDriver instance for each test and call driver.quit() after each test -> Option D
  4. Quick Check:

    Separate driver per test + quit to avoid conflicts [OK]
Hint: New driver per test + quit after test avoids conflicts [OK]
Common Mistakes:
  • Sharing one driver instance across tests
  • Not quitting driver causing resource leaks
  • Relying on manual process killing
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