如何解决使用Selenium和ChromeDriver时出现TypeError:'module' object is not callable错误
错误原因与修复方案
报错是因为调用了不可执行的模块对象,触发点在初始化Chrome驱动的代码行。webdriver.chrome是Selenium封装的模块,不是可实例化的类,只有首字母大写的webdriver.Chrome才是可以调用的驱动类。
修复步骤
- 把代码中
driver = webdriver.chrome("./chromedriver", options=chrome_options)里的小写chrome改为大写Chrome即可解决报错。 - 若使用Selenium 4.6及更高版本,无需手动指定chromedriver路径,可直接写
driver = webdriver.Chrome(options=chrome_options),Selenium会自动匹配对应版本的驱动文件。
修复后完整代码:
from selenium import webdriver from selenium.webdriver.chrome.options import Options as Chromeoptions chrome_options = Chromeoptions() chrome_options.add_extension('Metamask.crx') driver = webdriver.Chrome("./chromedriver", options=chrome_options) driver.get("https://www.youtube.com") driver.quit()
内容的提问来源于stack exchange,提问作者Brian
相关产品推荐
相关产品推荐

