Bird
0
0

What will be the output of the following code snippet?

medium📝 Predict Output Q13 of 15
Selenium Python - Cross-Browser Testing
What will be the output of the following code snippet?
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
print(driver.title)
driver.quit()
AOpens a visible browser window and prints the title
BRaises an error because headless mode cannot get page title
CPrints an empty string because page is not loaded in headless mode
DPrints the title of the page 'Example Domain' without opening a browser window
Step-by-Step Solution
Solution:
  1. Step 1: Understand headless execution effect

    Headless mode runs browser without UI but fully loads pages and executes scripts.
  2. Step 2: Analyze code behavior

    The code loads 'https://example.com' and prints the page title. Headless mode does not prevent getting the title, so it prints 'Example Domain'.
  3. Final Answer:

    Prints the title of the page 'Example Domain' without opening a browser window -> Option D
  4. Quick Check:

    Headless loads page and gets title correctly [OK]
Quick Trick: Headless runs full browser without UI, so title is accessible [OK]
Common Mistakes:
  • Assuming headless mode blocks page loading
  • Expecting errors when accessing page title in headless
  • Thinking headless opens visible browser window

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes