问题:特定应用程序需要使用较旧版本的Chrome。示例:所需的chrome版本:87.0.4280.88,但我的系统有112.0.5615.137。系统Chrome版本不能降级。
当我尝试执行下载并安装87.0.4280.88的python脚本或robot脚本时出错。
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 87
Current browser version is 112.0.5615.137 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
工具:
- Python 3.11
- WebDriverManager
- Robotframework(non ride)
伪码
1.使用WebDriverManager -通过python下载并安装chromeversion XXX。
1.使用robotframework中的python脚本作为exec来“使用”最近下载的chrome。
我使用的示例代码:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager(version="87.0.4280.88").install())
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${URL} https://www.youtube.com/
*** Test Cases ***
Open YouTube Website
Create WebDriver Chrome executable_path=${CURDIR}/chrome_driver_init.py
Go To ${URL}
Maximize Browser Window
Close Browser
其他尝试:
import os
import argparse
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
# Parse command line arguments
parser = argparse.ArgumentParser(description="Run a Robot Framework test case with ChromeDriver 87")
parser.add_argument("test_case", help="Path to the Robot Framework test case file")
parser.add_argument("-r", "--results", help="Path to the directory where the test results will be saved")
parser.add_argument("--store-id", help="Store ID to be used in the test case")
parser.add_argument("--banner", help="Banner to be used in the test case")
parser.add_argument("--test-tag", help="Tag to be used for the test case")
args = parser.parse_args()
# Set the options for the ChromeDriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--ssl-protocol=TLSv1.2')
options.add_argument('--ssl-ciphers=EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH')
options.add_argument('--remote-debugging-port=9222')
# Set the path to the ChromeDriver executable as an environment variable
# driver_path = "./.cache/selenium/chromedriver/mac-arm64/87.0.4280.88"
# os.environ["webdriver.chrome.driver"] = driver_path
# Start the ChromeDriver
driver = webdriver.Chrome(ChromeDriverManager(version="87.0.4280.88").install(), options=options)
# Run the Robot Framework test
cmd_args = ["robot"]
if args.store_id:
cmd_args.extend(["--variable", f"STORE_ID:{args.store_id}"])
if args.banner:
cmd_args.extend(["--variable", f"BANNER:{args.banner}"])
if args.test_tag:
cmd_args.extend(["--tag", args.test_tag])
if args.results:
cmd_args.extend(["--outputdir", args.results])
cmd_args.append(args.test_case)
driver.close()
os.environ.pop("webdriver.chrome.driver")
exit_code = os.system(" ".join(cmd_args))
exit(exit_code)
1条答案
按热度按时间8yoxcaq71#
你真的需要有GoogleChrome和Chromedriver。快速搜索,返回此site,并为不同的系统(如MacOS)提供下载。
您可以尝试将其安装在与系统不同的单独位置。然后使用脚本更改PATH,使其比系统的PATH先找到。
(just上一篇:为什么一个应用程序需要旧版本的GoogleChrome?为什么不使用Safari或Firefox?这将在未来给予问题,因为你已经有了。)