Bird
Raised Fist0
Selenium Pythontesting~20 mins

Edge configuration in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Edge Configuration 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 Edge WebDriver configuration code?
Consider the following Python Selenium code snippet configuring Edge WebDriver. What will be printed when this code runs successfully?
Selenium Python
from selenium import webdriver
from selenium.webdriver.edge.options import Options

options = Options()
options.use_chromium = True
options.add_argument('--headless')
options.add_argument('--disable-gpu')

driver = webdriver.Edge(options=options)
print(driver.capabilities['browserName'])
driver.quit()
A"chrome"
B"edge"
C"firefox"
D"safari"
Attempts:
2 left
💡 Hint
Check the browserName capability for Edge when using Chromium-based EdgeDriver.
❓ locator
intermediate
1:30remaining
Which locator strategy is best for stable Edge WebDriver tests?
You want to locate a button with text "Submit" on a webpage using Edge WebDriver. Which locator is the most stable and recommended?
Adriver.find_element('id', "submit")
Bdriver.find_element('css selector', "button.submit-btn")
Cdriver.find_element('xpath', "//button[text()='Submit']")
Ddriver.find_element('class name', "btn")
Attempts:
2 left
💡 Hint
IDs are unique and less likely to change compared to classes or text.
❓ assertion
advanced
2:00remaining
Which assertion correctly verifies Edge browser is running in headless mode?
Given an Edge WebDriver instance configured with headless mode, which assertion correctly checks this setting?
Selenium Python
from selenium import webdriver
from selenium.webdriver.edge.options import Options

options = Options()
options.add_argument('--headless')
driver = webdriver.Edge(options=options)
Aassert '--headless' in driver.capabilities['ms:edgeOptions']['args']
Bassert 'headless' in driver.capabilities['browserName']
Cassert driver.capabilities['headless'] == True
Dassert driver.execute_script('return navigator.webdriver') == False
Attempts:
2 left
💡 Hint
Check the Edge-specific options in capabilities for the headless argument.
🔧 Debug
advanced
2:30remaining
Why does this Edge WebDriver code raise a SessionNotCreatedException?
Review the code below. Why does it raise a SessionNotCreatedException when run?
Selenium Python
from selenium import webdriver
from selenium.webdriver.edge.options import Options

options = Options()
options.use_chromium = False

driver = webdriver.Edge(options=options)
driver.quit()
ABecause the Edge browser is not installed on the system
BBecause Edge WebDriver does not support options parameter
CBecause use_chromium is set to False but the installed EdgeDriver only supports Chromium-based Edge
DBecause options object is missing required arguments for Edge
Attempts:
2 left
💡 Hint
Check compatibility between EdgeDriver and browser versions regarding Chromium usage.
❓ framework
expert
3:00remaining
How to configure pytest to run tests only on Edge with headless mode?
You want to run Selenium tests using pytest only on Edge browser in headless mode. Which pytest fixture configuration is correct?
Selenium Python
import pytest
from selenium import webdriver
from selenium.webdriver.edge.options import Options

@pytest.fixture
 def driver():
  options = Options()
  options.add_argument('--headless')
  driver = webdriver.Edge(options=options)
  yield driver
  driver.quit()
A
@pytest.fixture
 def driver():
  options = Options()
  options.add_argument('--disable-gpu')
  driver = webdriver.Edge(options=options)
  yield driver
  driver.quit()
B
@pytest.fixture
 def driver():
  options = Options()
  options.use_chromium = False
  driver = webdriver.Edge(options=options)
  yield driver
  driver.quit()
C
@pytest.fixture
 def driver():
  driver = webdriver.Edge()
  yield driver
  driver.quit()
D
@pytest.fixture
 def driver():
  options = Options()
  options.add_argument('--headless')
  driver = webdriver.Edge(options=options)
  yield driver
  driver.quit()
Attempts:
2 left
💡 Hint
Headless mode requires adding the '--headless' argument to Edge options.

Practice

(1/5)
1. What is the main purpose of using Options() in Edge configuration with Selenium?
easy
A. To specify the location of the Edge driver executable
B. To set browser settings like headless mode or window size
C. To write test assertions for Edge browser
D. To locate web elements on the page

Solution

  1. Step 1: Understand the role of Options()

    Options() is used to configure browser settings such as running in headless mode or setting window size.
  2. Step 2: Differentiate from Service()

    Service() is used to specify the driver location, not browser settings.
  3. Final Answer:

    To set browser settings like headless mode or window size -> Option B
  4. Quick Check:

    Options() sets browser settings = A [OK]
Hint: Options() controls browser settings like headless mode [OK]
Common Mistakes:
  • Confusing Options() with Service()
  • Thinking Options() locates elements
  • Assuming Options() writes test assertions
2. Which of the following is the correct way to create an Edge driver with headless mode enabled in Python Selenium?
easy
A. options = Options() options.add_argument('--headless') driver = webdriver.Edge(options=options)
B. service = Service() service.add_argument('--headless') driver = webdriver.Edge(service=service)
C. driver = webdriver.Edge('--headless')
D. driver = webdriver.Edge(options='--headless')

Solution

  1. Step 1: Use Options() to add headless argument

    Create an Options object and add the '--headless' argument using add_argument().
  2. Step 2: Pass options to Edge driver constructor

    Pass the options object to webdriver.Edge() using the options parameter.
  3. Final Answer:

    options = Options() options.add_argument('--headless') driver = webdriver.Edge(options=options) -> Option A
  4. Quick Check:

    Options() + add_argument('--headless') + driver = Edge(options=options) = A [OK]
Hint: Use Options() and add_argument('--headless') for headless mode [OK]
Common Mistakes:
  • Trying to add arguments to Service()
  • Passing string directly to webdriver.Edge()
  • Using wrong parameter names
3. What will be the output of the following code snippet?
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options

options = Options()
options.add_argument('--window-size=800,600')
service = Service('path/to/msedgedriver')
driver = webdriver.Edge(service=service, options=options)
print(driver.execute_script('return window.innerWidth + "," + window.innerHeight'))
driver.quit()
medium
A. "800,600"
B. "1024,768"
C. SyntaxError
D. RuntimeError

Solution

  1. Step 1: Analyze the options argument

    The code sets the window size to 800x600 using --window-size=800,600.
  2. Step 2: Understand the JavaScript execution

    The script returns the current window inner width and height as a string separated by a comma.
  3. Final Answer:

    "800,600" -> Option A
  4. Quick Check:

    Window size set to 800x600, script returns "800,600" = C [OK]
Hint: Window size argument sets innerWidth and innerHeight [OK]
Common Mistakes:
  • Assuming default window size is returned
  • Confusing Service() with Options()
  • Expecting syntax or runtime errors
4. Identify the error in the following Edge driver setup code:
from selenium import webdriver
from selenium.webdriver.edge.options import Options

options = Options()
options.add_argument('--headless')
driver = webdriver.Edge(options=options, executable_path='msedgedriver.exe')
medium
A. Missing import for Service class
B. Options() cannot be used with headless argument
C. Using 'executable_path' parameter is deprecated; should use Service()
D. Driver initialization syntax is correct

Solution

  1. Step 1: Check driver initialization parameters

    The executable_path parameter is deprecated in recent Selenium versions for Edge.
  2. Step 2: Use Service() to specify driver location

    The correct way is to create a Service object with the driver path and pass it via the service parameter.
  3. Final Answer:

    Using 'executable_path' parameter is deprecated; should use Service() -> Option C
  4. Quick Check:

    Use Service() for driver path, not executable_path [OK]
Hint: Use Service() for driver path, not executable_path [OK]
Common Mistakes:
  • Using deprecated executable_path parameter
  • Not importing Service class
  • Thinking Options() disallows headless
5. You want to run Edge browser tests in headless mode with a custom user agent and a specific driver path. Which code snippet correctly configures this setup?
hard
A. from selenium import webdriver options = Options() options.add_argument('--headless') options.add_argument('--user-agent=MyCustomAgent') driver = webdriver.Edge(options=options)
B. from selenium import webdriver options = Options() options.headless = True options.user_agent = 'MyCustomAgent' driver = webdriver.Edge(executable_path='C:/drivers/msedgedriver.exe', options=options)
C. from selenium import webdriver service = Service('C:/drivers/msedgedriver.exe') driver = webdriver.Edge(service=service) driver.add_argument('--headless') driver.add_argument('user-agent=MyCustomAgent')
D. from selenium import webdriver from selenium.webdriver.edge.service import Service from selenium.webdriver.edge.options import Options options = Options() options.add_argument('--headless') options.add_argument('--user-agent=MyCustomAgent') service = Service('C:/drivers/msedgedriver.exe') driver = webdriver.Edge(service=service, options=options)

Solution

  1. Step 1: Add headless and user-agent arguments to Options()

    Use add_argument() to add both '--headless' and '--user-agent=MyCustomAgent' correctly.
  2. Step 2: Specify driver path using Service()

    Create a Service object with the driver path and pass it to webdriver.Edge() via the service parameter.
  3. Step 3: Verify correct usage of parameters

    from selenium import webdriver options = Options() options.headless = True options.user_agent = 'MyCustomAgent' driver = webdriver.Edge(executable_path='C:/drivers/msedgedriver.exe', options=options) incorrectly uses deprecated executable_path and wrong attribute names. from selenium import webdriver service = Service('C:/drivers/msedgedriver.exe') driver = webdriver.Edge(service=service) driver.add_argument('--headless') driver.add_argument('user-agent=MyCustomAgent') tries to add arguments to driver object which is invalid. from selenium import webdriver options = Options() options.add_argument('--headless') options.add_argument('--user-agent=MyCustomAgent') driver = webdriver.Edge(options=options) misses driver path specification.
  4. Final Answer:

    from selenium import webdriver from selenium.webdriver.edge.service import Service from selenium.webdriver.edge.options import Options options = Options() options.add_argument('--headless') options.add_argument('--user-agent=MyCustomAgent') service = Service('C:/drivers/msedgedriver.exe') driver = webdriver.Edge(service=service, options=options) -> Option D
  5. Quick Check:

    Options add_argument + Service for driver path = D [OK]
Hint: Use Options add_argument and Service for driver path [OK]
Common Mistakes:
  • Using deprecated executable_path instead of Service
  • Adding arguments to driver instead of Options
  • Missing driver path in configuration
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