如何使用 Python 解决 Selenium:TypeError: 'module' object is not callable [英] How to resolve Selenium with Python: TypeError: 'module' object is not callable
问题描述
我是 Selenium/Python 的新手,练习很少.在 pycharm 中运行我的 Selenium/Python 程序时收到以下错误.请帮忙.
C:\Users\rk.marav\PycharmProjects\RadhaSelenium\venv\Scripts\python.exe C:/Users/rk.marav/PycharmProjects/RadhaSelenium/Tests/mainTest.py回溯(最近一次调用最后一次):文件C:/Users/rk.marav/PycharmProjects/RadhaSelenium/Tests/mainTest.py",第 13 行,在 <module> 中.m.main()文件 "C:/Users/rk.marav/PycharmProjects/RadhaSelenium/Tests/mainTest.py", line 10, in maindriver.getbrowserInstance()文件C:\Users\rk.marav\PycharmProjects\RadhaSelenium\executionEngine\DriverScript.py",第 25 行,在 getbrowserInstancedriver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')类型错误:模块"对象不可调用主要测试开始...IE浏览器调用开始进程以退出代码 1 结束
下面是我的代码:
DriverScript.py:
class driverScript:def __init__(self,browser=None):如果浏览器是无:浏览器 = {}别的:self.browser = 浏览器打印(self.browser)#self.constants = Constants()def getbrowserInstance(self):# 创建一个新的 IE 会话print("浏览器调用开始")如果(self.browser=='IE'):driver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')driver.maximize_window()driver.implicitly_wait(5)driver.delete.allcookies()print("浏览器被调用")driver.get("http://www.store.demoqa".com")
mainTest.py
from executionEngine.DriverScript import driverScript从 Utilities.Constants 导入常量从硒导入网络驱动程序类 mainTest(driverScript):定义主(自我):print("主测试开始...")driver = driverScript('IE')driver.getbrowserInstance()m = mainTest()m.main()
此错误信息...
driver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')类型错误:模块"对象不可调用
...暗示 webdriver.ie 是一个模块,不可调用.
@JohnGordon 的分析非常正确.selenium.webdriver.ie.webdriver
是 Selenium 相关Python 模块并且不可调用.
发起一个internet-explorer 通过 selenium-iedriver 的会话您需要用大写的 I
替换小的 i
.因此,您的代码行将是:
driver = webdriver.Ie(executable_path=r'C:\Selenium\Drivers\IEDriverServer.exe')
<块引用>
I am new to Selenium/Python and practicing few exercises. I am receiving below error when running my Selenium/Python program in pycharm. Please help.
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
Below is my code:
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()
This error message...
driver = webdriver.ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe')
TypeError: 'module' object is not callable
...implies that the webdriver.ie is a module and is not callable.
@JohnGordon was pretty correct in his analysis. selenium.webdriver.ie.webdriver
is one of the Selenium related Python Module and is not callable.
To initiate an internet-explorer session through selenium-iedriver you need to replace the small i
with capital I
. So effectively your line of code will be:
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")
这篇关于如何使用 Python 解决 Selenium:TypeError: 'module' object is not callable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!