如何使用Python解决Selenium:类型错误:"模块"对象不可调用



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

C:Usersrk.maravPycharmProjectsRadhaSeleniumvenvScriptspython.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:Usersrk.maravPycharmProjectsRadhaSeleniumexecutionEngineDriverScript.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是一个模块,不可调用

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

要通过 selenium-iedriver 启动互联网浏览器会话,您需要将小i替换为大写I。因此,您的代码行将有效地:

driver = webdriver.Ie(executable_path=r'C:SeleniumDriversIEDriverServer.exe')

您可以在TypeError中找到相关讨论: 'module' 对象是不可调用的错误 driver=webdriver("C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe"(

相关内容

  • 没有找到相关文章

最新更新