5

我有以下代码

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()

不幸的是,当我运行上面的 Python 脚本时,Selenium 非常礼貌地完全忽略了我想使用的事实,Chromium而是使用我的默认Google Chrome. 需要明确的是,它完全按照脚本指定的方式执行,只是它使用的是 Chrome 而不是 Chromium。

显然,我做错了什么。我的尝试基于以下页面。

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

我需要做什么才能将Chromium Web 浏览器与 Selenium(在 Python 中)一起使用?

4

1 回答 1

14

desired_capabilities选项用于传递给通用 selenium 驱动程序代码的选项。chrome 驱动程序使用的选项,包括 chrome 或 chromium 二进制位置,使用chrome_options如下方式传入:

from selenium.webdriver.chrome.options import Options
opts = Options()
opts.binary_location = chromium_path
driver = webdriver.Chrome(chrome_options=opts)
于 2013-08-23T12:52:24.837 回答