Raf*_* C. 1 python oop python-2.7
我的场景
我只有一个带有两种方法的类。在第一种方法中,我将值存储在变量中。在第二种方法中,我尝试调用这些变量
class UpdateTallysheet(Page):
def confirme_status_capture_exp_value(self):
self.select_dropdown_value(EventsLocators.STATUS, "8")
value_1 = self.find_element(EventsLocators.EXAM_EXP_VALUE).get_attribute("value")
value_2 = self.find_element(EventsLocators.PANO_EXP_VALUE).get_attribute("value")
value_3 = self.find_element(EventsLocators.TREATMENT_EXP_VALUE).get_attribute("value")
self.find_element(EventsLocators.SAVE_BUTTON).click()
WebDriverWait(self.driver, AUTOCOMPLETE_TIMEOUT).until(
EC.text_to_be_present_in_element((By.CLASS_NAME, "success"), 'Event updated successfully'))
self.find_element(EventsLocators.TALLYSHEET_LINK).click()
def fill_date(self):
self.select_current_date(EventsLocators.DATE_RECEIVED, EventsLocators.CURRENT_DATE)
self.select_current_date(EventsLocators.DATE_COMPLETED, EventsLocators.CURRENT_DATE)
print self.value_1
Run Code Online (Sandbox Code Playgroud)
我的错误
AttributeError: 'UpdateTallysheet' 对象没有属性 'value_1'
如何value_1
在另一种方法中使用该变量?
您需要使用以下命令将其设置为实例变量self
:
class UpdateTallysheet(Page):
def confirme_status_capture_exp_value(self):
self.select_dropdown_value(EventsLocators.STATUS, "8")
self.value_1 = self.find_element(EventsLocators.EXAM_EXP_VALUE).get_attribute("value")
self.value_2 = self.find_element(EventsLocators.PANO_EXP_VALUE).get_attribute("value")
self.value_3 = self.find_element(EventsLocators.TREATMENT_EXP_VALUE).get_attribute("value")
Run Code Online (Sandbox Code Playgroud)
然后您可以通过使用在另一种方法中使用它 self.value_1