使用Selenium和Python进行铬测试
我有以下代码使用Selenium和Python进行铬测试,python,selenium,selenium-webdriver,chromium,Python,Selenium,Selenium Webdriver,Chromium,我有以下代码 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
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非常礼貌地完全忽略了我想要使用Chrome
的事实,而是使用默认的GoogleChrome
。要清楚的是,它完全按照脚本指定的方式执行,只是它使用的是Chrome而不是Chrome
显然,我做错了什么。我的尝试是基于以下几页
使用带有Selenium(Python)的Chromiumweb浏览器需要做什么?所需的功能
选项用于传递给通用Selenium驱动程序代码的选项。chrome驱动程序使用的选项,包括chrome或chrome二进制位置,使用chrome\u选项传递,如下所示:
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.binary_location = chromium_path
driver = webdriver.Chrome(chrome_options=opts)