2016-12-21 4 views
-1

내 시나리오같은 클래스

에 다른 방법에서 변수를 호출하면 난 단지 두 가지 방법으로 하나 개의 클래스가 있습니다. 첫 번째 방법에서는 변수에 값을 저장합니다. 두 번째 방법에서 나는 이러한 변수

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' object has no attribute 'value_1' 

이 어떻게 다른 방법으로 변수 value_1를 사용할 수있는 전화하려고?

답변

3

당신은 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

+0

근무 윌를 사용하여 다른 방법으로 사용할 수 있습니다. 고마워. – RFtests

+1

도와 드리겠습니다! 또한,'__init __()'메소드는 필요하지 않을 수도 있지만, 정리 유지에 도움이된다는 것을 알았습니다. 다음을 참조하십시오 : http://stackoverflow.com/questions/8609153/why-do-we-use-init-in-python-classes – Will

+0

동일한 문제가 다시 발생합니다. 여기 내 코드를 참조하십시오. https : // gist .github.com/anonymous/61e2a757b451871867964966a36940d5 그리고 'AttributeError :'CreateContractor '객체에'firstname'' 속성이 없습니다. 오류가 있습니까? – RFtests