Bird
0
0

You want to run Selenium tests headlessly on a CI server but also capture screenshots on failure. Which approach correctly combines headless mode with screenshot capture in Python?

hard📝 Application Q8 of 15
Selenium Python - CI/CD Integration
You want to run Selenium tests headlessly on a CI server but also capture screenshots on failure. Which approach correctly combines headless mode with screenshot capture in Python?
AEnable headless mode via options and call driver.save_screenshot() on failure
BDisable headless mode to allow screenshots, then call driver.save_screenshot()
CUse headless mode and call driver.get_screenshot_as_text() instead
DHeadless mode disables screenshots; use a different tool
Step-by-Step Solution
Solution:
  1. Step 1: Confirm headless mode supports screenshots

    Headless browsers can capture screenshots normally using save_screenshot().
  2. Step 2: Combine headless with screenshot on failure

    Enable headless via options, then call save_screenshot() when test fails.
  3. Final Answer:

    Enable headless mode via options and call driver.save_screenshot() on failure -> Option A
  4. Quick Check:

    Headless + save_screenshot() works for CI failure capture [OK]
Quick Trick: Headless supports screenshots; use save_screenshot() [OK]
Common Mistakes:
  • Thinking screenshots need GUI
  • Using get_screenshot_as_text() wrongly
  • Believing headless disables screenshots

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes