python selenium4 报错 :Cant instantiate abstract class Service with abstract method command_line_args代码为:from seleniumwebdrivercommonservice import Service wd_service = ServicerCUsersgaoyuDesktopgoogle2
这个错误是因为Selenium 4中Service类是一个抽象类,无法直接实例化。您需要使用具体的子类来创建Service对象。
在Selenium 4中,您可以使用ChromeService类来创建ChromeDriver的Service对象。示例如下:
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
# 创建ChromeDriver的Service对象
wd_service = Service(r"C:\Users\gaoyu\Desktop\google2\driver\chromedriver.exe")
# 创建ChromeDriver对象
driver = webdriver.Chrome(service=wd_service)
# 使用driver进行后续操作
请确保您已经安装了Selenium 4和ChromeDriver,并且将路径替换为您实际的ChromeDriver路径。
原文地址: https://www.cveoy.top/t/topic/in9X 著作权归作者所有。请勿转载和采集!