使用Selenium和Python进行Chromium测试

Ste*_*gle 4 python selenium chromium selenium-webdriver

我有以下代码

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()
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我运行上面的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中)需要做什么?

小智 11

desired_capabilities选项用于传递给一般selenium驱动程序代码的选项.chrome驱动程序使用的选项,包括chrom(e | ium)二进制位置,使用chrome_options如下传递:

from selenium.webdriver.chrome.options import Options
opts = Options()
opts.binary_location = chromium_path
driver = webdriver.Chrome(chrome_options=opts)
Run Code Online (Sandbox Code Playgroud)