How To Set Chrome Options headless disable-gpu

801 views
Skip to first unread message

Brian Carpio

unread,
Oct 11, 2018, 1:29:08 PM10/11/18
to capybara-py
In Ruby I can set the headless option for Chrome, but I can't seem to figure out how to do this with the Python implementation. 

Capybara.register_driver(:headless_chrome) do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu] }
  )

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: capabilities
  )
end

Ian Lesperance

unread,
Oct 11, 2018, 2:44:21 PM10/11/18
to capybara-py
Here's what the test suite does:

import capybara

@capybara.register_driver("selenium_chrome_headless")
def init_selenium_chrome_headless_driver(app):
    from capybara.selenium.driver import Driver
    from selenium.webdriver.chrome.options import Options

    chrome_options = Options()
    chrome_options.add_argument("--headless")

    return Driver(app, browser="chrome", chrome_options=chrome_options)

I haven't tried it with --disable-gpu, but I'd imagine you'd use add_argument() to configure that as well.

Brian Carpio

unread,
Oct 11, 2018, 2:57:28 PM10/11/18
to capybara-py
Thanks,

I should have updated this, but I actually like your implementation!

@capybara.register_driver("selenium")
def init_selenium_driver(app):
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--window-size=1920x1080")
    chrome_options.add_argument("--disable-gpu")
    from capybara.selenium.driver import Driver

    return Driver(app, browser="chrome", options=chrome_options)
Reply all
Reply to author
Forward
0 new messages