Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing with Chromium using Selenium and Python

I have the following code

import time

from selenium import webdriver
import selenium.webdriver.chrome.service as service

chromedriver_path = "/Users/stephen/Downloads/chromedriver2_mac32_0.8/chromedriver"

chromium_path = "/Users/stephen/Downloads/chrome-mac/Chromium.app/Contents/MacOs/Chromium"

service = service.Service(chromedriver_path)
service.start()
capabilities = {'chrome.binary': chromium_path}
driver = webdriver.Remote(
    service.service_url,
    desired_capabilities=capabilities)
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
driver.quit()

Unfortunately, when I run the above Python script, Selenium very politely completely ignores the fact that I wanted to use Chromium and instead uses my default Google Chrome. To be clear, it does exactly what the script specifies, it is just that it is using Chrome and not Chromium.

Obviously, I am doing something wrong. I am basing my attempts off of the following pages.

https://code.google.com/p/chromedriver/wiki/GettingStarted

http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html?highlight=capabilities

What do I need to do to use the Chromium web browser with Selenium (in Python)?

like image 216
Stephen Cagle Avatar asked May 29 '13 06:05

Stephen Cagle


1 Answers

The desired_capabilities option is for options passed on to the general selenium driver code. Options used by the chrome driver, including the chrome or chromium binary location, are passed in using chrome_options as follows:

from selenium.webdriver.chrome.options import Options
opts = Options()
opts.binary_location = chromium_path
driver = webdriver.Chrome(chrome_options=opts)
like image 165
Iain Murray Avatar answered Nov 02 '22 02:11

Iain Murray