Python 我的按钮单击返回下一页对象显示错误模块对象不可调用

Python 我的按钮单击返回下一页对象显示错误模块对象不可调用,python,selenium-webdriver,webdriver,Python,Selenium Webdriver,Webdriver,我已经开始在网站的自动化脚本中使用页面对象模型。我正在使用Python,Webdriver 我有一个带有一些方法的LoginPage类 我有一个带有方法的AdministrationPage类。(当用户登录管理页面时显示) 在登录页面上,我有一个名为clickAdministration(self)的方法:。点击按钮在这里,返回页面为return Pages.administrationPage(self.driver) 当我的代码运行并到达clickAdministration时,将显示以下错

我已经开始在网站的自动化脚本中使用页面对象模型。我正在使用Python,Webdriver 我有一个带有一些方法的LoginPage类 我有一个带有方法的AdministrationPage类。(当用户登录管理页面时显示)

在登录页面上,我有一个名为clickAdministration(self)的方法:。点击按钮在这里,返回页面为return Pages.administrationPage(self.driver)

当我的代码运行并到达clickAdministration时,将显示以下错误:

    Traceback (most recent call last):
  File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore \TestCases\AdministrationPage_TestCase.py", line 31, in test_add_Project
    administration_page = login_page.clickAdministration()
  File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore \Pages\page.py", line 59, in clickAdministration
    return Pages.administrationPage(self.driver)
TypeError: 'module' object is not callable
我需要一些帮助,当我从LoginPage类中单击Administration按钮时,我调用Administration Page对象的语法不正确

当用户登录后(从LoginPage类)单击管理链接时,我应该返回AdministrationPage对象

我的LoginPage和AdministrationPage类位于名为Pages的包中 我的TestCase类位于一个名为TestCases的包中

您还会注意到,在我的代码片段中,我对WebDriverWait的调用被注释掉了。这是因为当我使用它时,会出现超时异常。我现在又开始使用时间了。 如果有人也能帮助我使用WebDriverWait语法,那会很有帮助。 多谢各位

我的代码截取如下:

TestCases\Administration页面_TestCase.py

    import unittest
import time
from selenium import webdriver
from Locators import locators
from Locators import element
from Pages import page
from Pages.administrationPage import AdministrationPage
from Pages.page import LoginPage


class AdministrationPage_TestCase(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Ie("C:\QA\Automation\Python_projects\Selenium Webdriver\IEDriverServer_Win32_2.45.0\IEDriverServer.exe")
        self.driver.get("http://riaz-pc.company.local:8080/clearcore")
        self.login_page = page.LoginPage(self.driver)
        print "I am here in setUp self.login_page = page.LoginPage(self.driver)"
        self.driver.implicitly_wait(30)

    def test_add_Project(self):
        login_page = page.LoginPage(self.driver)
        login_page.userLogin_valid()
        administration_page = login_page.clickAdministration()
        print "I am here administration_page = login_page.clickAdministration(self.driver)"
        administration_page.AdministrationPage.add_project()

    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    unittest.main()
Pages\administrationPage.py

import time
import datetime
from selenium.common.exceptions import NoSuchElementException
from Locators.locators import MainPageLocators
from Locators import locators
from Locators import element
from Locators.element import BasePageElement

class BasePage(object):

    def __init__(self, driver):
        self.driver = driver


class AdministrationPage(BasePage):
    # Add a project, enter project name & description, save
    def add_project(self):
        add_project_button = self.driver.find_element(*MainPageLocators.addButton_project)
        add_project_button.click()
        project_name_textfield = self.driver.find_element(*MainPageLocators.projectName_textfield)
        project_name_textfield.click()
        project_name_textfield.clear()
        dateNow = self.get_date_now()
        project_name_textfield.sendkeys('LADEMO_IE_nn_')
        project_description_textfield = self.driver.find_element(*MainPageLocators.projectDescription_textfield)
        project_description_textfield.click()
        project_description_textfield.clear()
        project_name_textfield.sendkeys("LADEMO create a basic project test script - Selenium Webdriver/Python Automated test")
Pages\page.py(这是LoginPage类)


导入页面。管理页面
异常消息不会试图愚弄您:)
来自页面。管理页面导入管理页面
返回管理页面(self.driver)
。顺便说一句,你的进口部分是一个完整的混乱,清理一下非常感谢你。我的同事开发人员也这么说。开发人员说我应该将我的类命名为与模块不同的类。我会的,我现在就让它工作。如果你把你的答案移到答案部分,我将能够勾选它并为你投票。
    import time
from selenium.common.exceptions import NoSuchElementException
from Locators.element import BasePageElement
from Locators.locators import MainPageLocators
from Locators import locators
from Locators import element
from Locators.element import BasePageElement
import Locators
import Pages.administrationPage


class BasePage(object):

    def __init__(self, driver):
        self.driver = driver


class LoginPage(BasePage):
    def click_go_button(self):
        element = self.driver.find_element(*MainPageLocators.GO_BUTTON)
        element.click()

    def userLogin_valid(self):
        time.sleep(5)
        userName_textbox = self.driver.find_element(*MainPageLocators.usernameTxtBox)
        userName_textbox.clear()
        userName_textbox.send_keys("user1")
        password_textbox = self.driver.find_element(*MainPageLocators.passwordTxtBox)
        password_textbox.clear()
        password_textbox.send_keys("test123")
        submitButton = self.driver.find_element(*MainPageLocators.submitButton)
        submitButton.click()

    #Click Administration from top menu
    def clickAdministration(self):
        # getting Timeout exception when i use this, using sleep for now
        #WebDriverWait (self.driver, 10).until(lambda d: self.driver.find_element(*MainPageLocators.AdministrationButton_xpath).click()) 
        time.sleep(15)
        self.driver.find_element(*MainPageLocators.AdministrationButton_xpath).click()
        time.sleep(5)
        print "I am here, trying to click Pages.administrationPage"
        return Pages.administrationPage(self.driver)

    def user_login_invalid(self):
        userName_textbox = self.driver.find_element(*MainPageLocators.usernameTxtBox)
        userName_textbox.clear()
        userName_textbox.send_keys("user1")
        password_textbox = self.driver.find_element(*MainPageLocators.passwordTxtBox)
        password_textbox.clear()
        password_textbox.send_keys("test1")
        submitButton = self.driver.find_element(*MainPageLocators.submitButton)
        submitButton.click()

    #check if Administration link is present.  When logged in we can check are we on the correct page
    def isAdministration_present(self):
        #administrationLink = self.driver.find_element(*MainPageLocators.AdministrationButton_xpath)
        #print "administrationLink = " + administrationLink
        #wait = WebDriverWait(self.driver, 10)
        #h3 = wait.until(EC.visibility_of_element_located(*MainPageLocators.AdministrationButton_xpath))
        #h3.click()
        #print h3.text
        time.sleep(10)
        try:
            administrationLink_text = self.driver.find_element(*MainPageLocators.AdministrationButton_xpath)
        except NoSuchElementException, e:
            return False
        return "Administration" in administrationLink_text.text # check if the text Administration is in the AdministrationLink_text, return true if it is
        #print "administrationLink_text.text = " + administrationLink_text.text


    def is_text_present(self):
        try:
            #body = self.driver.find_element_by_tag_name("body") # find body tag element
            administrationLink_text = self.driver.find_element(*MainPageLocators.AdministrationButton_xpath)
        except NoSuchElementException, e:
            return False
        return "Administration" in administrationLink_text.text # check if the text is in the Administration Link