Python Selenium 'module' 对象在 python selenium 脚本中不可调用

标签 python selenium

学习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/

相关文章:

python - 应用引擎 : cached reference property?

selenium - 使用 Jenkins 运行 headless firefox Xvfb 以运行 Selenium 测试

python - Windows 7下Selenium无法启动FirefoxDriver : Can't load profile

java - 如何使用java + selenium设置chrome浏览器语言?

c# - Selenium:查找基本 Url

python - 我如何在Python中将这个字符串变成2个数组?

python - 附加到上一行

javascript - 如何从 Java 中的 JavascriptExecutor.executeScript() 方法返回值

python - Django 迁移外键 django.db.utils.OperationalError : (1005, "Can' t create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)") 错误

python - 在 Julia 中加速 kNN 函数