How to address TypeError: 'module' object is not callable error using Selenium and ChromeDriver

How to address TypeError: 'module' object is not callable error using Selenium and ChromeDriver

代码试验:

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()

这是我编写的代码,但出现此错误:

TypeError: 'module' object is not callable.

有人可以帮我解决这个问题吗?

chrome是一个模块。相反,您需要调用 Chrome() 作为 webdriver.Chrome()

您的有效代码行将是:

driver = webdriver.Chrome("./chromedriver", options=chrome_options)

参考资料

您可以在以下位置找到一些相关的详细讨论:

  • TypeError: 'module' object is not callable error with driver=webdriver("C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe")