'Fills form fields with values.
@param fields A list of dicts that specifies the fields to fill.'

def fill_fields(self, fields):

    browser = self.browser
    for field_spec in fields:
        value = field_spec['value']
        for query_type in ('xpath', 'class', 'name', 'id'):
            if (query_type in field_spec.keys()):
                field = getattr(browser, ('find_element_by_' + query_type))
                field = field(field_spec[query_type])
        if (('label' in field_spec) and ('name' in field_spec)):
            splitted_label = field_spec['label'].split()
            xpath = "//*[contains(@for,'{name}')    ".format(**field_spec)
            for word in splitted_label:
                xpath += (("and    contains(text(),    '" + word) + "')    ")
            xpath = (xpath + ']')
            field = browser.find_element_by_xpath(xpath)
        elif ('label' in field_spec):
            xpath = '//*[    '
            splitted_label = field_spec['label'].split()
            for word in splitted_label[0:(-1)]:
                xpath += (("contains(text(),    '" + word) + "')    and    ")
            xpath = (((xpath + "contains(text(),    '") + splitted_label[(-1)]) + "')]")
            field = browser.find_element_by_xpath(xpath)
        if isinstance(value, basestring):
            field.send_keys(value)
        elif (isinstance(value, bool) and value):
            field.click()
