How to use headless Chrome browser with selenium(python)

Using Chrome Headless

The first thing you need to do to switch to Chrome is to install Chrome if you don’t have it yet (obviously!), and then you need to install ChromeDriver, which is the little bit of glue that allows Selenium to send commands to Chrome and automate it. If you are on a Mac, then brew install chromedriver is all you need to do. On other platforms, download an installer from the ChromeDriver site:

To switch to Chrome, you just need to change the initialization of the client variable:

client = webdriver.Chrome()

But this will still use a regular Chrome window. If you want to use the headless option, you have to add options:

options = webdriver.ChromeOptions()
client = webdriver.Chrome(chrome_options=options)

If you want to switch back to the regular mode, just comment out the options.add_argument('headless') line and you’ll get a visible window that you can watch while the tests run.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: