<s> from saunter . po . webdriver . element import Element <EOL> class NoSuchDayException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DatePicker ( Element ) : <EOL> """<STR_LIT>""" <EOL> def __set__ ( self , obj , val ) : <EOL> """<STR_LIT>""" <EOL> _how_many_clicks = <NUM_LIT:0> <EOL> click_to_open = obj . driver . find_element_by_locator ( self . locator ) <EOL> click_to_open . click ( ) <EOL> datepicker = obj . driver . find_element_by_id ( '<STR_LIT>' ) <EOL> year_element = datepicker . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> current_year = year_element . text <EOL> year_difference = int ( current_year ) - val [ '<STR_LIT>' ] <EOL> _how_many_clicks += year_difference * <NUM_LIT:12> <EOL> month_element = datepicker . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> current_month = month_element . text <EOL> months = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> current_month_number = months . index ( current_month ) + <NUM_LIT:1> <EOL> month_difference = current_month_number - val [ '<STR_LIT>' ] <EOL> _how_many_clicks += month_difference <EOL> if _how_many_clicks != <NUM_LIT:0> : <EOL> if _how_many_clicks < <NUM_LIT:0> : <EOL> _how_many_clicks = abs ( _how_many_clicks ) <EOL> month_mover_locator = '<STR_LIT>' <EOL> else : <EOL> month_mover_locator = '<STR_LIT>' <EOL> for x in range ( <NUM_LIT:0> , _how_many_clicks ) : <EOL> month_mover = datepicker . find_element_by_css_selector ( month_mover_locator ) <EOL> month_mover . click ( ) <EOL> has_date = datepicker . find_elements_by_xpath ( '<STR_LIT>' % val [ '<STR_LIT>' ] ) <EOL> if len ( has_date ) == <NUM_LIT:1> : <EOL> has_date [ <NUM_LIT:0> ] . click ( ) <EOL> else : <EOL> raise NoSuchDayException ( ) <EOL> def __get__ ( self , obj , cls = None ) : <EOL> locator_type = locator [ : locator . find ( "<STR_LIT:=>" ) ] <EOL> if locator_type not in [ '<STR_LIT>' , '<STR_LIT:id>' ] : <EOL> raise saunter . exceptions . InvalidLocatorString ( locator ) <EOL> locator_value = locator [ locator . find ( "<STR_LIT:=>" ) + <NUM_LIT:1> : ] <EOL> if locator_type == '<STR_LIT>' : <EOL> _locator = locator_value <EOL> elif locator_type == '<STR_LIT:id>' : <EOL> _locator = '<STR_LIT>' % locator_value <EOL> current_date = obj . driver . execute_script ( '<STR_LIT>' , _locator ) <EOL> return current_date </s>
