Bird
Raised Fist0
Selenium Pythontesting~20 mins

WebDriver setup (ChromeDriver, GeckoDriver) in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
WebDriver Setup 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 WebDriver setup code?
Consider the following Python code snippet that sets up a Chrome WebDriver and opens a webpage. What will be printed after execution?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='/path/to/chromedriver')
driver = webdriver.Chrome(service=service)
driver.get('https://example.com')
print(driver.title)
driver.quit()
AExample Domain
BChromeDriver
Chttps://example.com
Dselenium.common.exceptions.WebDriverException
Attempts:
2 left
💡 Hint
The driver.title returns the title of the current page loaded by the browser.
❓ assertion
intermediate
1:30remaining
Which assertion correctly verifies the page title after WebDriver opens a page?
You want to check that the page title is exactly 'Welcome Page' after opening a URL with Selenium WebDriver in Python. Which assertion is correct?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='/path/to/chromedriver')
driver = webdriver.Chrome(service=service)
driver.get('https://example.com/welcome')
# Which assertion below is correct?
Aassert driver.title != 'Welcome Page'
Bassert driver.title == 'Welcome Page'
Cassert 'Welcome Page' in driver.current_url
Dassert driver.page_source == 'Welcome Page'
Attempts:
2 left
💡 Hint
The page title is accessed by driver.title, not current_url or page_source.
🔧 Debug
advanced
2:30remaining
Why does this GeckoDriver setup code raise an error?
This Python code tries to start Firefox WebDriver but raises an error. Identify the cause.
Selenium Python
from selenium import webdriver
from selenium.webdriver.firefox.service import Service

service = Service('/path/to/geckodriver')
driver = webdriver.Firefox(service=service)
driver.get('https://example.com')
driver.quit()
AFirefox browser is not installed on the system
BThe Service class is not imported from selenium.webdriver.firefox.service
CThe path to geckodriver is incorrect or missing execute permission
Ddriver.get() method is deprecated and causes error
Attempts:
2 left
💡 Hint
Check if the geckodriver executable path is valid and accessible.
❓ locator
advanced
1:30remaining
Which locator strategy is best for stable element selection in Selenium?
You want to select a button element that has a unique id 'submit-btn' on a webpage. Which locator is best practice for stability and speed?
Adriver.find_element('id', 'submit-btn')
Bdriver.find_element('xpath', '//button[@id="submit-btn"]')
Cdriver.find_element('css selector', 'button#submit-btn')
Ddriver.find_element('class name', 'submit-btn')
Attempts:
2 left
💡 Hint
Using id locator is usually fastest and most reliable if id is unique.
❓ framework
expert
3:00remaining
What is the correct way to initialize ChromeDriver with options in Selenium Python?
You want to start ChromeDriver with headless mode enabled and disable GPU usage. Which code snippet correctly sets this up?
A
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service('/path/to/chromedriver')
driver = webdriver.Chrome(service=service)
driver.add_argument('--headless')
driver.add_argument('--disable-gpu')
driver.get('https://example.com')
B
from selenium import webdriver
options = webdriver.ChromeOptions()
options.headless = True
options.disable_gpu = True
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
C
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.set_headless(True)
options.set_disable_gpu(True)
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
D
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
service = Service('/path/to/chromedriver')
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://example.com')
Attempts:
2 left
💡 Hint
Options must be created and passed to the driver constructor before starting the browser.

Practice

(1/5)
1. What is the main purpose of using ChromeDriver or GeckoDriver in Selenium Python?
easy
A. To connect Selenium scripts with the browser for automation
B. To write test cases in Python
C. To create HTML reports of test results
D. To manage database connections during tests

Solution

  1. Step 1: Understand WebDriver role

    WebDriver acts as a bridge between Selenium scripts and the browser.
  2. Step 2: Identify driver purpose

    ChromeDriver and GeckoDriver are specific drivers to control Chrome and Firefox browsers respectively.
  3. Final Answer:

    To connect Selenium scripts with the browser for automation -> Option A
  4. Quick Check:

    Driver connects Selenium to browser = B [OK]
Hint: Drivers link Selenium to browsers for automation [OK]
Common Mistakes:
  • Thinking drivers write test cases
  • Confusing drivers with reporting tools
  • Assuming drivers manage databases
2. Which of the following is the correct way to import and set up ChromeDriver using Selenium 4+ in Python?
easy
A. from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('path/to/chromedriver') driver = webdriver.Chrome(service=service)
B. import webdriver driver = webdriver.Chrome('path/to/chromedriver')
C. from selenium.webdriver import ChromeDriver service = ChromeDriver('path/to/chromedriver') driver = webdriver.Chrome(service)
D. from selenium import webdriver service = webdriver.Chrome('path/to/chromedriver') driver = webdriver.Chrome(service)

Solution

  1. Step 1: Check import statements

    Correct import for Service class is from selenium.webdriver.chrome.service import Service.
  2. Step 2: Verify driver initialization

    Driver must be created with webdriver.Chrome(service=service) passing the Service object.
  3. Final Answer:

    from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('path/to/chromedriver') driver = webdriver.Chrome(service=service) -> Option A
  4. Quick Check:

    Use Service class and pass to Chrome() = A [OK]
Hint: Use Service class and pass it to Chrome() constructor [OK]
Common Mistakes:
  • Passing driver path directly to Chrome() without Service
  • Wrong import paths for Service
  • Using incorrect class names like ChromeDriver
3. What will happen if you run this code snippet?
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service('wrong/path/chromedriver')
driver = webdriver.Chrome(service=service)
driver.get('https://example.com')
medium
A. The browser opens and loads the page successfully
B. The driver automatically downloads the correct ChromeDriver
C. A FileNotFoundError or WebDriverException is raised due to wrong driver path
D. The code runs but the page does not load

Solution

  1. Step 1: Analyze driver path usage

    Service is given a wrong path to ChromeDriver executable.
  2. Step 2: Understand error on invalid path

    Selenium cannot find the driver file, so it raises an error like FileNotFoundError or WebDriverException.
  3. Final Answer:

    A FileNotFoundError or WebDriverException is raised due to wrong driver path -> Option C
  4. Quick Check:

    Wrong driver path causes error = D [OK]
Hint: Wrong driver path causes immediate error [OK]
Common Mistakes:
  • Assuming driver auto-downloads
  • Expecting browser to open without driver
  • Thinking code runs but page stays blank
4. Identify the error in this GeckoDriver setup code and choose the correct fix:
from selenium import webdriver
service = Service('path/to/geckodriver')
driver = webdriver.Firefox(service=service)
driver.get('https://example.com')
medium
A. webdriver.Firefox() does not accept service parameter
B. Missing import of Service class from selenium.webdriver.firefox.service
C. Incorrect driver path format, should use double backslashes
D. driver.get() should be called before creating driver

Solution

  1. Step 1: Check imports

    Service class for Firefox must be imported from selenium.webdriver.firefox.service.
  2. Step 2: Verify usage

    Without importing Service, the code will raise NameError or similar.
  3. Final Answer:

    Missing import of Service class from selenium.webdriver.firefox.service -> Option B
  4. Quick Check:

    Import Service for Firefox driver = C [OK]
Hint: Always import Service class for the browser driver used [OK]
Common Mistakes:
  • Not importing Service class
  • Wrong path format causing silent failure
  • Calling driver.get() before driver creation
5. You want to run Selenium tests on Firefox but your Firefox browser updated to version 115. Which is the best practice to ensure your GeckoDriver setup works correctly?
hard
A. Remove the Service class and pass the driver path directly to webdriver.Firefox()
B. Use the existing GeckoDriver without changes; Selenium handles compatibility automatically
C. Switch to ChromeDriver since GeckoDriver does not support Firefox 115
D. Download the GeckoDriver version compatible with Firefox 115 and update the Service path accordingly

Solution

  1. Step 1: Understand driver-browser compatibility

    GeckoDriver must match the Firefox browser version to work properly.
  2. Step 2: Apply best practice for updates

    Download the correct GeckoDriver version for Firefox 115 and update your code to use its path.
  3. Final Answer:

    Download the GeckoDriver version compatible with Firefox 115 and update the Service path accordingly -> Option D
  4. Quick Check:

    Match driver version with browser version = A [OK]
Hint: Always match driver version with browser version [OK]
Common Mistakes:
  • Assuming Selenium auto-updates drivers
  • Switching browsers unnecessarily
  • Passing driver path without Service class
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