TypeError:WebDriver.__init__()在Selenium Python中获得了意外的关键字参数'executable_path'

nkoocmlb  于 11个月前  发布在  Python
关注(0)|答案(3)|浏览(4451)

我的代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

option = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path='./chromedriver.exe', options=option)

driver.get('https://www.google.com/')

输出:

WebDriver.__init__() got an unexpected keyword argument 'executable_path'

我正在尝试创建一个脚本来登录到一个网站。当我尝试运行这个脚本时,它给了我这个错误:WebDriver.__init__() got an unexpected keyword argument 'executable_path'

zujrkrfu

zujrkrfu1#

这是由于selenium4.10.0中的更改:https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

请注意,executable_path已被删除。
如果你想传入一个executable_path,你现在必须使用service参数。

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
pepwfjgg

pepwfjgg2#

如果您不希望手动设置driver.exe路径,只需删除executable_path(见下文)。使用最新的selenium(v4.6.0及更高版本),其内置工具SeleniumManger可以下载并处理driver.exe(如果您没有指定)。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = option)

driver.get('https://www.google.com/')
hujrc8aj

hujrc8aj3#

注意:从参数中删除executable_url,因为您已经安装了最新版本Selenium,如果您有4.6.0以上的selenium,则无需添加executable_url,并且在最新版本的Selenium中,您无需下载webdriver

只需复制下面的代码并运行你的python文件simple

from selenium import webdriver

driver=webdriver.Chrome()

driver.get("https://www.facebook.com/")

相关问题