学习Python驱动的Selenium,在我的实践中我不断收到以下错误。我陷入困境,需要一些指导
Traceback (most recent call last): File "test_login.py", line 14, in test_Login loginpage = homePage(self.driver) TypeError: 'module' object is not callable
这是我的代码
test_login.py
import unittest
import homePage
from selenium import webdriver
class Login(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("https://hub.docker.com/login/")
def test_Login(self):
loginpage = homePage(self.driver)
loginpage.login(email,password)
def tearDown(self):
self.driver.close()
if __name__ == '__main__': unittest.main()
homePage.py
from selenium.webdriver.common.by import By
class BasePage(object):
def __init__(self, driver):
self.driver = drive
class LoginPage(BasePage):
locator_dictionary = {
"userID": (By.XPATH, '//input[@placeholder="Username"]'),
"passWord": (By.XPATH, '//input[@placeholder="Password"]'),
"submittButton": (By.XPATH, '//button[text()="Log In"]'),
}
def set_userID(self, id):
userIdElement = self.driver.find_element(*LoginPage.userID)
userIdElement.send_keys(id)
def login_error_displayed(self):
notifcationElement = self.driver.find_element(*LoginPage.loginError)
return notifcationElement.is_displayed()
def set_password(self, password):
pwordElement = self.driver.find_element(*LoginPage.passWord)
pwordElement.send_keys(password)
def click_submit(self):
submitBttn = self.driver.find_element(*LoginPage.submitButton)
submitBttn.click()
def login(self, id, password):
self.set_password(password)
self.set_email(id)
self.click_submit()
感谢任何帮助
最佳答案
我想这里:
loginpage = homePage(self.driver)
您打算实例化 LoginPage
类:
loginpage = homePage.LoginPage(self.driver)
关于Python Selenium 'module' 对象在 python selenium 脚本中不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39733650/