TypeError: WebDriver.init() got an unexpected keyword argument 'service'
TypeError: WebDriver.__init__() got an unexpected keyword argument 'service'
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
关注让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
问题分析: 该错误提示表明,在使用WebDriver的init()方法时,出现了一个关键字参数“service”的意外问题。可能是该参数不应该在init()方法中使用,或者该参数的使用方式不正确。 解决方案:- 检查代码中是否使用了错误的参数名。 检查代码中使用init()方法的地方,确认是否使用了错误的参数名,确保所有使用的参数名都与WebDriver支持的参数名一致。例如,如果想使用服务对象,应该使用“service_”参数而不是“service”。 正确的用法示例:
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('/path/to/chromedriver') options = webdriver.ChromeOptions() options.add_argument('--start-maximized') driver = webdriver.Chrome(service=service, options=options) driver.get('https://www.google.com')- 检查WebDriver和浏览器驱动的版本是否兼容。 确保使用的WebDriver版本与浏览器驱动版本兼容。有时不兼容的版本可能会导致该错误。 例如,如果您使用的是Chrome浏览器版本83,则需要下载ChromeDriver 83或更高版本。
- 检查使用的参数是否正确创建了WebDriver对象。 如果上述两个解决方案都没有解决问题,则可能是因为创建WebDriver对象时使用的参数不正确。请确保使用正确的参数创建WebDriver对象。 正确的用法示例:
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('/path/to/chromedriver') options = webdriver.ChromeOptions() options.add_argument('--start-maximized') driver = webdriver.Chrome(service=service, options=options) driver.get('https://www.google.com')检查代码是否正确创建了WebDriver对象,包括使用的参数是否正确,并重试代码。 参考资料: - https://stackoverflow.com/questions/59243520/typeerror-webdriver-init-got-an-unexpected-keyword-argument-service
解决 无用评论 打赏 举报