Robotframework - 如何使用旧的 chromedriver

问题描述 投票:0回答:1

问题: 特定应用程序需要使用旧版本的 chrome。 示例:所需的 chrome 版本:87.0.4280.88,但我的系统有 112.0.5615.137。系统Chrome版本无法降级

当我尝试执行下载并安装 87.0.4280.88 的 python 脚本或机器人脚本时出错。

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

工具:

  1. Python 3.11
  2. WebDriverManager
  3. Robotframework(非乘坐)

伪代码

  1. 使用 WebDriverManager - 通过 python 下载并安装 chromeversion XXX。
  2. 使用 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)
python google-chrome selenium-webdriver selenium-chromedriver robotframework
1个回答
0
投票

你真的需要有 GoogleChrome 和 chromedriver。快速搜索,返回此 site,其中包含适用于不同系统(例如 MacOS)的下载。

您可以尝试将其安装在与系统不同的单独位置。然后使用脚本更改 PATH,使其比系统的更先找到它。

(只是评论:为什么一个应用程序需要旧版本的 GoogleChrome?为什么不使用 Safari 或 Firefox?这将在未来带来问题,因为您已经遇到了。)

© www.soinside.com 2019 - 2024. All rights reserved.