0

I am getting the following error in my Python Selenium Webdriver script.

Error
Traceback (most recent call last):
  File "C:\Webdriver\ClearCore 501\TestCases\VariablesPage_TestCase.py", line 87, in test_add_variables
    variablesPage = projectnavigator.select_projectNavigator_item("Variables") # Select the Variables link from the left hand Project Navigator, it returns the Variables page object
  File "C:\Webdriver\ClearCore 501\Menus\project_navigator.py", line 24, in select_projectNavigator_item
    variables_projectnavigator_link = self.driver.find_element(*MainPageLocators.variables_project_navigator_link2).click()
AttributeError: type object 'MainPageLocators' has no attribute 'variables_project_navigator_link2'

I think it is because the class has not been instantiated. You cannot access a member variable without an instance of the class. I think I have instantiated my class like this:

projectnavigator = project_navigator.ProjectNavigatorPage(self.driver)

I do not know why I am getting the error.

My code snippet is as follows:

class ProjectNavigatorPage

    # This class defines the methods for the the ClearCore left hand project navigator
# i.e. Selecting the Data Objects, Datasets, Variables, Feeds, Mappings, Data Previews etc

import time
from Pages.base import BasePage
#from Pages.login import LoginPage
from Pages.admin import AdministrationPage
from Locators.locators import MainPageLocators
from Pages.variables import VariablesPage

class ProjectNavigatorPage(BasePage):

    # Select an item from the Project Navigator  e.g. Data Objects tab, Datasets, Variables etc
    def select_projectNavigator_item(self, menu_item):
        if menu_item == "Data Objects":
            #LoginPage.clickAdministration()
            #self.clickAdministration(self)
            pass
        elif menu_item == "Datasets":
            pass
        elif menu_item == "Variables":
            variables_projectnavigator_link = self.driver.find_element(*MainPageLocators.variables_project_navigator_link2).click()
            return VariablesPage(self.driver)

        elif menu_item == "Feeds":
            pass
        elif menu_item == "Mappings":
            pass
        elif menu_item == "Data Previews":
            pass

class VariablesPage_TestCase

    # This class defines the tests for the the Variables page.  e.g. Add a variable, Name, Address, DOB

import unittest
import time
import datetime
from selenium import webdriver
from Locators import locators, Globals
from Locators import element
from Menus import project_navigator
from Pages import login
from Pages import admin
from Pages import main_dashboard
from Pages import data_objects, variables
from Menus import toolbar
from Pages import datamaps
from Pages import datasets
from Pages import base
from Utilities import Utilities
from Pages import data_previews
from Pages import data_objects_saved_page
import datetime
from selenium.webdriver.support.ui import Select

class VariablesPage_TestCase(unittest.TestCase):

    def setUp(self):
        #webdriver.DesiredCapabilities.FIREFOX["unexpectedAlertBehaviour"] = "accept"
        webdriver.DesiredCapabilities.INTERNETEXPLORER["unexpectedAlertBehaviour"] = "accept"
        #self.driver = webdriver.Firefox()
        #self.driver = webdriver.Ie("C:\QA\Automation\Python_projects\Selenium Webdriver\IEDriverServer_Win32_2.45.0\IEDriverServer.exe")
        self.driver = webdriver.Ie(Globals.IEdriver_path)
        self.driver.get(Globals.URL_justin_pc)
        self.login_page = login.LoginPage(self.driver)
        self.driver.implicitly_wait(100)


    def test_add_variables(self):
        print "*** Test add Variables ***"
        data_dashboard_page = self.login_page.userLogin_valid(Globals.login_username, Globals.login_password)
        md = main_dashboard.MainDashboardPage(self.driver)
        #main_dashboard.MainDashboardPage.select_project_from_drop_down(self)
        md.select_project_from_drop_down()
        data_configuration_page = data_dashboard_page.click_data_configuration2() # Click Data Configuration from the Project Navigator
        #assert data_dashboard_page.is_Data_Configuration_pageDisplayed(), "Data Configuration Page not displayed"
        print "data_configuration_page.is_Data_Configuration_pageDisplayed()"
        #print data_dashboard_page.is_Data_Configuration_pageDisplayed()
        time.sleep(10)
        assert data_configuration_page.is_Data_Configuration_pageDisplayed(), "Data Configuration Page not displayed"
        if data_configuration_page.is_Data_Configuration_pageDisplayed() == True:
            pass
        else:
           print "ERROR - Data Configuration page is not displayed"
       # tool_bar = toolbar.ToolbarPage(self.driver)
        projectnavigator = project_navigator.ProjectNavigatorPage(self.driver)
        variablesPage = projectnavigator.select_projectNavigator_item("Variables") # Select the Variables link from the left hand Project Navigator, it returns the Variables page object

class Locators

    from selenium.webdriver.common.by import By

class MainPageLocators(object):
    usernameTxtBox = (By.ID, 'unid')
    passwordTxtBox = (By.ID, 'pwid')
    submitButton = (By.ID, 'button')

    # Data Configuration page
    DataConfiguration_button_xpath = (By.XPATH, '//div[. = "Data Configuration"]')
    data_config_elementTxt = (By.XPATH, '//span[contains(@title, "Data Configuration")][text()="Data Configuration"]')
    data_config_elementTxt2 = (By.XPATH, '//span[@title="Data Configuration"]')

    # Variables page
    variables_title_page_text = (By.XPATH, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[5]/div/div[3]/div/div[4]/div/div[2]/div/div[2]/div/div/span') # This is the text beside the Add button (Variables)
    variables_project_navigator_link = (By.XPATH, '//span[@title="variables" and contains(text(), "variables")]')
    variables_projet_navigator_link2 = (By.XPATH, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[5]/div/div[3]/div/div[2]/div/div/div/div/div/div/div[1]/div/div[2]/div/div[1]/div[3]/div[1]/div/div[2]/div/div[2]/span')
    variables_page_no_data_to_display_text = (By.XPATH, '//div[@class="gwt-Label absoluteLeft padding" and contains(text(), "No data to display")]') # This is the text where it says No data to display when you land on the variables page

1 Answer 1

2

There is a spelling/typo mistake while declaring variable

variables_projet_navigator_link2 = (By.XPATH, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[5]/div/div[3]/div/div[2]/div/div/div/div/div/div/div[1]/div/div[2]/div/div[1]/div[3]/div[1]/div/div[2]/div/div[2]/span')

variables_projet_navigator_link2 should be variables_project_navigator_link2

Sign up to request clarification or add additional context in comments.

1 Comment

Yes i just managed to spot that. Silly hey, corrected it and it works now. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.