Selenium Webdriver Python AttributeError类型对象没有属性

编程入门 行业动态 更新时间:2024-10-26 01:25:59
本文介绍了Selenium Webdriver Python AttributeError类型对象没有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Python Selenium Webdriver脚本中遇到以下错误.

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.

我的代码段如下:

ProjectNavigatorPage类

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

类变量Page_TestCase

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

类定位器

from selenium.webdrivermon.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

推荐答案

声明变量时出现拼写错误/拼写错误

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应该是variables_project_navigator_link2

更多推荐

Selenium Webdriver Python AttributeError类型对象没有属性

本文发布于:2023-10-22 08:16:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   对象   类型   Webdriver   Selenium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!