Bird
0
0

Given this Python code snippet connecting to a Selenium Docker container, what will be the output if the container is not running?

medium📝 Predict Output Q13 of 15
Selenium Python - CI/CD Integration
Given this Python code snippet connecting to a Selenium Docker container, what will be the output if the container is not running?
from selenium import webdriver
from selenium.common.exceptions import WebDriverException

try:
    driver = webdriver.Remote(
        command_executor='http://localhost:4444/wd/hub',
        options=webdriver.ChromeOptions()
    )
    print("Connected")
except WebDriverException:
    print("Connection failed")
AConnection failed
BConnected
CSyntaxError
DTimeoutError
Step-by-Step Solution
Solution:
  1. Step 1: Understand connection attempt

    The code tries to connect to Selenium server at localhost:4444.
  2. Step 2: Consider container not running

    If the container is down, connection fails and WebDriverException is raised, triggering except block.
  3. Final Answer:

    Connection failed -> Option A
  4. Quick Check:

    Container down causes WebDriverException = "Connection failed" [OK]
Quick Trick: If container off, connection throws WebDriverException [OK]
Common Mistakes:
  • Expecting 'Connected' even if container is off
  • Confusing exception types
  • Thinking code has syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes