安装多版本selenium
在 Python 中处理包的多个版本 |作者:跳过 |中等 (medium.com)
如何在一个python 文件用两个不同版本的库_python 有两个库,怎么在代码中选择用哪个库-CSDN博客
安装3.14.0版本pip install selenium==3.14.0 --target=C:\selenium\3.14.0
安装 4.12.0版本
pip install selenium==4.12.0 --target=C:\selenium\4.12.0
测试脚本
# -*- coding: UTF-8 -*- import os import sys import time selenium_version = 3 if selenium_version == 3: sys.path.insert(1, os.path.abspath(r'C:\selenium\3.14.0')) import selenium print(selenium.__version__) from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from webdriver_manager.chrome import ChromeDriverManager options = webdriver.ChromeOptions() options.add_argument("--ignore-certificate-error") options.add_argument("--ignore-ssl-errors") driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) driver.maximize_window() driver.get("https://www.baidu.com/") driver.find_element_by_id('kw').send_keys('python') driver.find_element_by_id('su').click() time.sleep(2) driver.quit() # print(sys.path) # for key in list(sys.modules.keys()): # if key.startswith('selenium'): # del sys.modules[key] elif selenium_version == 4: sys.path.insert(1, os.path.abspath(r'C:\selenium\4.12.0')) import selenium print(selenium.__version__) from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By options = webdriver.ChromeOptions() options.add_argument("--ignore-certificate-error") options.add_argument("--ignore-ssl-errors") driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options) driver.maximize_window() driver.get("https://www.baidu.com/") driver.find_element(By.ID, 'kw').send_keys('python') driver.find_element(By.ID, 'su').click() time.sleep(2) driver.quit() # print(sys.path)
标签:库多,webdriver,python,selenium,driver,sys,共存,import,options From: https://www.cnblogs.com/daizichuan/p/17752250.html