一種方式是與Options
類中定義的功能定位:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.binary_location = r'C:/chromium-48/chrome.exe'
driver = webdriver.Chrome(chrome_options=options)
或DesiredCapabilities
:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capa = DesiredCapabilities.CHROME;
capa['chromeOptions'] = {
'binary': r'C:/chromium-48/chrome.exe',
'args': []
}
driver = webdriver.Chrome(desired_capabilities=capa)
但是,如果你正在尋找一個可擴展的解決方案,那麼你應該設置不同版本的網格:
java -jar selenium-server-standalone-2.53.1.jar -role hub -host 0.0.0.0 -port 4444
java -jar selenium-server-standalone-2.53.1.jar
-role node
-hub http://localhost:4444/grid/register
-browser platform=WINDOWS,browserName=chrome,version=48,chrome_binary="C:/chromium-48/chrome.exe"
java -jar selenium-server-standalone-2.53.1.jar
-role node
-hub http://localhost:4444/grid/register
-browser platform=WINDOWS,browserName=chrome,version=54,chrome_binary="C:/chromium-54/chrome.exe"
然後,您可以直接在功能選擇的版本:
from selenium import webdriver
capa = {'browserName': 'chrome', 'version': '48', 'platform': 'ANY'}
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=capa)
請參閱此-https://stackoverflow.com/questions/3785991/can-i-run-multiple-versions-of-google-chrome-on-the- same-machine-mac-or-window – demouser123
似乎[ChromeOptions對象]中有一個'binary'選項(https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-chromeOptions-object ),用於配置Chrome二進制文件的路徑。儘管這似乎只與本地Chrome實例有關。這個選項在集線器或遠程獨立服務器上運行似乎沒有意義,因爲應該在ChromeDriver side_(傳遞給_selenium server_)上配置多個版本到路徑映射,而ChromeOptions應該提供一個'version'配置(或一樣)指示服務器選擇二進制文件。 –
這個有一步一步的幫助https://e4example.blogspot.com/2017/07/run-different-version-of-chrome-using.html – Nabin