Selenium中executable_path已弃用,新手求助如何改用Service对象?
解决Selenium中executable_path弃用的警告问题
Selenium 4.x版本起,executable_path参数已被弃用,必须通过Service对象来指定浏览器驱动的路径,修改驱动初始化代码即可消除警告。
修改后的完整代码:
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.service import Service # 创建Service实例,传入chromedriver路径 service = Service('./chromedriver') # 将Service对象传入Chrome构造方法 driver = webdriver.Chrome(service=service)
小提示:如果你的ChromeDriver已经添加到系统环境变量中,无需手动指定路径,直接写service = Service()即可,Selenium会自动查找驱动文件。
内容的提问来源于stack exchange,提问作者Leo Szac
相关产品推荐
相关产品推荐

