How to resolve Selenium with Python: TypeError: 'module' object is not callable

How to resolve Selenium with Python: TypeError: 'module' object is not callable

我是 Selenium/Python 的新手,练习很少。当 运行 我的 Selenium/Python 程序在 pycharm 时,我收到以下错误。请帮忙。

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

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

这个错误信息...

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

...意味着 webdriver.ie 是一个模块并且不是 callable.

@JohnGordon 的分析非常正确。 selenium.webdriver.ie.webdriver related Python Module 之一,不可 调用

要启动 session through ,您需要将小 i 替换为大写 I。所以实际上你的代码行将是:

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

You can find a relevant discussion in TypeError: 'module' object is not callable error with driver=webdriver(“C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe”)