如何解决TypeError:无法在pycharm中使用Python通过Selenium调用'module'对象
from selenium import webdriver
driver=webdriver.firefox("D:\Pycharm_automation\geckodriver-v0.27.0-win64\geckodriver.exe")
driver.get("google.com")
- 执行时,我遇到类型错误。我无法打开Firefox和Chrome驱动程序。
- 我已经安装了chrome和gecko驱动程序。
解决方法
我的脚本旁边就是我的“ geckodriver.exe”。
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
import time
opts = Options()
browser = Firefox(options=opts)
browser.get("www.google.de")
,
此错误消息...
TypeError: 'module' object is not callable
...表示您的代码正在尝试调用不可调用的 firefox 模块。
firefox
是webdriver
模块中的子模块。
解决方案
相反,您需要致电Firefox()
。您需要将firefox
替换为 Firefox
。实际上,您的代码块将是:
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'D:\Pycharm_automation\geckodriver-v0.27.0-win64\geckodriver.exe')
driver.get("google.com")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。