selenium TypeError:在MacOS上使用Selify的ChromeDriver和Chrome中出现无法调用的错误

4uqofj5v  于 2022-11-10  发布在  Mac
关注(0)|答案(3)|浏览(148)

当我尝试测试我的测试应用程序以查看Selify Chrome是否工作时,我收到以下错误:

driver= webdriver.chrome("/usr/local/bin/chromedriver")
 TypeError: 'module' object is not callable

我检查了一下是不是安装了

/usr/local/bin/chromedriver --version
ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310})

但即使在重新启动计算机后,我仍然收到错误。
我的环境是:

  • Mac OS Catalina(10.15.6)
  • Chrome版本:84.0.4147.89
  • PyCharm Pro

出什么问题了?

c3frrgcw

c3frrgcw1#

webdriver.Chrome区分大小写。现在,您会看到这个错误,因为您无意中试图调用模块webdriver.chrome
如果将代码更改为

driver = webdriver.Chrome("/usr/local/bin/chromedriver")

您应该不会再收到此错误。

wwwo4jvm

wwwo4jvm2#

此错误消息...

TypeError: 'module' object is not callable

...暗示有一个typeerror调用了chrome模块。
根据您使用的代码尝试:

driver= webdriver.chrome()

这里,pythonchrome解释为webdriver的子模块:

解决方案

相反,您需要如下调用selenium.webdriver.chrome.webdriver类方法,最好使用keyexecutable_path,如下所示:

driver= webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
                  ^ note the uppercase C
nimxete2

nimxete23#

驱动程序=webdriver.chrome(“/usr/local/bin/chromedriver”)
这应该是DIVER=webdriver.Chrome(“/usr/local/bin/chromedriver”)

相关问题