【问题标题】:How to resolve Selenium with Python: TypeError: 'module' object is not callable如何使用 Python 解决 Selenium:TypeError:“模块”对象不可调用
【发布时间】:2020-04-26 05:33:19
【问题描述】:

我是 Selenium/Python 的新手,并且练习了一些练习。在 pycharm 中运行我的 Selenium/Python 程序时,我收到以下错误。请帮忙。

C:\Users\rk.marav\PycharmProjects\RadhaSelenium\venv\Scripts\python.exe C:/Users/rk.marav/PycharmProjects/RadhaSelenium/Tests/mainTest.py
Traceback (most recent call last):
  File "C:/Users/rk.marav/PycharmProjects/RadhaSelenium/Tests/mainTest.py", line 13, in <module>
    m.main()
  File "C:/Users/rk.marav/PycharmProjects/RadhaSelenium/Tests/mainTest.py", line 10, in main
    driver.getbrowserInstance()
  File "C:\Users\rk.marav\PycharmProjects\RadhaSelenium\executionEngine\DriverScript.py", line 25, in getbrowserInstance
    driver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')
TypeError: 'module' object is not callable
Main Test started...
IE
Browser invoke started

Process finished with exit code 1

下面是我的代码:

DriverScript.py:

class driverScript:

    def __init__(self,browser=None):
         if browser is None:
             browser = {}
         else:
             self.browser = browser
             print(self.browser)

         #self.constants = Constants()

    def getbrowserInstance(self):
        # create a new IE session
        print("Browser invoke started")
        if (self.browser=='IE'):
           driver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')
           driver.maximize_window()
           driver.implicitly_wait(5)
           driver.delete.allcookies()
           print("Browser is Invoked")
           driver.get("http://www.store.demoqa"
                       ".com")

ma​​inTest.py

from executionEngine.DriverScript import driverScript
from Utilities.Constants import Constants
from selenium import webdriver

class mainTest(driverScript):

    def main(self):
        print("Main Test started...")
        driver = driverScript('IE')
        driver.getbrowserInstance()

m = mainTest()
m.main()

【问题讨论】:

  • webdriver.ie 是一个模块。你叫错了。你想要webdriver.Ie 代替(注意大写I。)有关更多详细信息,请参阅stackoverflow.com/a/24925868/494134
  • 大写字母很重要
  • 为什么不继承Selenium这个类?
  • 变量和函数名称应遵循lower_case_with_underscores 样式。我投票决定关闭它,因为它似乎是一个错字/琐碎。
  • 谢谢约翰。非常感谢。问题就解决了。

标签: python selenium module typeerror callable


【解决方案1】:

此错误消息...

    driver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')
TypeError: 'module' object is not callable

...暗示 webdriver.ie 是一个模块,不能callable

@JohnGordon 的分析非常正确。 selenium.webdriver.ie.webdriver 是与Selenium 相关的Python Module 之一,并且不可可调用

要通过 启动 会话,您需要将小i 替换为大写I。因此,您的代码行将是:

driver = webdriver.Ie(executable_path=r'C:\Selenium\Drivers\IEDriverServer.exe')

您可以在TypeError: 'module' object is not callable error with driver=webdriver(“C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe”)找到相关讨论

【讨论】:

    猜你喜欢
    • 2012-05-26
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    相关资源
    最近更新 更多