date_time_value.py (1516B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 class DateTimeValue: 7 """ 8 Interface for setting the value of HTML5 "date" and "time" input elements. 9 10 Simple usage example: 11 12 :: 13 14 element = marionette.find_element(By.ID, "date-test") 15 dt_value = DateTimeValue(element) 16 dt_value.date = datetime(1998, 6, 2) 17 18 """ 19 20 def __init__(self, element): 21 self.element = element 22 23 @property 24 def date(self): 25 """ 26 Retrieve the element's string value 27 """ 28 return self.element.get_attribute("value") 29 30 # As per the W3C "date" element specification 31 # (http://dev.w3.org/html5/markup/input.date.html), this value is formatted 32 # according to RFC 3339: http://tools.ietf.org/html/rfc3339#section-5.6 33 @date.setter 34 def date(self, date_value): 35 self.element.send_keys(date_value.strftime("%Y-%m-%d")) 36 37 @property 38 def time(self): 39 """ 40 Retrieve the element's string value 41 """ 42 return self.element.get_attribute("value") 43 44 # As per the W3C "time" element specification 45 # (http://dev.w3.org/html5/markup/input.time.html), this value is formatted 46 # according to RFC 3339: http://tools.ietf.org/html/rfc3339#section-5.6 47 @time.setter 48 def time(self, time_value): 49 self.element.send_keys(time_value.strftime("%H:%M:%S"))