从同一类中的另一个方法调用变量 [英] Calling a variable from another method in the same class
本文介绍了从同一类中的另一个方法调用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的场景
我只有一个带有两种方法的类.在第一种方法中,我将值存储在变量中.在第二种方法中,我尝试调用这些变量
I only have one class with two methods. In the first method I store values in a variable. In the second method I try to call these variables
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
我的错误
AttributeError: 'UpdateTallysheet' 对象没有属性 'value_1'
AttributeError: 'UpdateTallysheet' object has no attribute 'value_1'
如何在另一种方法中使用变量 value_1
?
How can I use the variable value_1
in another method?
推荐答案
需要使用self
将其设置为实例变量:
You need to set it to an instance variable by using 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")
然后你可以通过使用 self.value_1
这篇关于从同一类中的另一个方法调用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文