【问题标题】:TypeError: 'module' object is not callable using Seleniumthrough Python in pycharmTypeError:“模块”对象不能在 pycharm 中通过 Python 使用 Selenium 调用
【发布时间】:2020-09-14 09:47:15
【问题描述】:
from selenium import webdriver

driver=webdriver.firefox("D:\Pycharm_automation\geckodriver-v0.27.0-win64\geckodriver.exe")
driver.get("google.com")
  1. 在执行时,我遇到了类型错误。我无法打开 Firefox 和 chrome 驱动程序。
  2. 我已经安装了 chrome 和 gecko 驱动程序。

【问题讨论】:

  • 尝试将路径中的\ 替换为\\

标签: python-3.x selenium-webdriver firefox webdriver geckodriver


【解决方案1】:

我的“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:__init__() 需要 1 个位置参数,但给出了 2 个”
  • 你能发布回溯吗?
【解决方案2】:

此错误消息...

TypeError: 'module' object is not callable

...暗示您的代码正在尝试调用不可调用的 firefox 模块。

firefoxwebdriver 模块中的子模块。


解决方案

您需要致电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")

【讨论】:

    猜你喜欢
    • 2020-05-24
    • 2019-08-24
    • 2022-08-03
    • 2020-11-06
    • 1970-01-01
    • 2017-05-08
    • 2019-01-28
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多