我有Chrome v75。以下代码返回错误。
selenium.webdriver.Chrome(service_log_path='NUL', executable_path=info['location'] + '/Variables/Common/Browsers/chromedriver.exe', options=ops, desired_capabilities={'binary_location': 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'})
和错误
*** selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome version must be between 70 and 73
如何安装2个版本的Chrome? (在1个Windows配置文件上)
我尝试了可移植的Chrome版本,但chromedriver无法接受Chrome.exe。
请帮助!谢谢,
答案 0 :(得分:0)
如果我理解正确,我认为您无法使用带有2个版本的chrome的单一配置文件。但是,只要您还能够调整Chrome驱动程序和Chrome Binary的正确路径,就可以调整个人资料以使用多个版本。
下面是一个使用单个配置文件的示例,以及一个多配置文件的示例,通过该示例我们可以在字典中遍历键,值对,并在我们的方法中使用这些调整。
单个配置文件
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def single_profile():
""" Initiate Chrome Options """
options = webdriver.ChromeOptions()
""" Set Driver and Binary Path """
options.binary_location = r'C:/chromium-version-XX/chrome.exe'
driver_path='C:/path/to/chromedriver-version-XX.exe'
""" Create Chrome instance with our parameters """
driver = webdriver.Chrome(chrome_options=options, executable_path=driver_path)
if __name__ == '__main__':
single_profile()
多配置文件
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def multi_profile(binary, chromedriver):
""" Initiate Chrome Options """
options = webdriver.ChromeOptions()
""" Set Driver and Binary Path """
options.binary_location = binary
driver_path = chromedriver
""" Create Chrome instance with our parameters """
driver = webdriver.Chrome(chrome_options=options, executable_path=driver_path)
if __name__ == '__main__':
profiles = {
"chromedriver-version-1" : "chromebinary-version-1",
"chromedriver-version-2": "chromebinary-version-2"
}
""" loop through our dict into our method """
""" Note: use profiles.iteritems(): for python 2.X """
for chromedriver, binary in profiles.items():
multi_profile(binary, chromedriver)