示例#1
0
 def __getitem__(self, index):
     try:
         return super(ElementList, self).__getitem__(index)
     except IndexError:
         raise ElementDoesNotExist(
             'no elements could be find with %s "%s"' %
             (self.find_by, self.query))
示例#2
0
    def fill_and_submit_form(form_id, use_js_submit=False, **fields):
        try:
            form = browser.find_by_id(form_id).first
        except ElementDoesNotExist as find_exec:
            info_text = 'available forms: ' + ', '.join([
                '<id:%s, class:%s>' % (f['id'], f['class'])
                for f in browser.find_by_tag('form')
            ])
            raise ElementDoesNotExist('%s - %s' % (find_exec, info_text))

        for k, v in fields.iteritems():
            input_element = form.find_by_name(k).first
            if isinstance(v, basestring) and v.startswith('select:'):
                for select_value in v[7:].split(','):
                    input_element.select(select_value)
            elif isinstance(v, basestring) and v.startswith('check:'):
                check, value = v.split(':')
                if value.lower() == 'true':
                    input_element.check()
                else:
                    input_element.uncheck()
            else:
                input_element.fill(v)

        if use_js_submit:
            browser.execute_script("document.getElementById('%s').submit();" %
                                   form_id)
        else:
            form.find_by_tag('button').first.click()
示例#3
0
 def __getitem__(self, index):
     if not isinstance(index, int) and not isinstance(index, slice):
         return self.first[index]
     try:
         return self._container[index]
     except IndexError:
         raise ElementDoesNotExist(
             u'no elements could be found with {0} "{1}"'.format(
                 self.find_by, self.query))
示例#4
0
 def __getitem__(self, index):
     if not isinstance(index, int):
         return self.first[index]
     try:
         return super(ElementList, self).__getitem__(index)
     except IndexError:
         raise ElementDoesNotExist(
             'no elements could be found with {0} "{1}"'.format(
                 self.find_by, self.query))
示例#5
0
    def click_css(self, css, sleep_after_find=0):

        for index in six.moves.range(self.wait_time_in_seconds):
            try:
                element = self.browser.find_by_css(css).first
                if element:
                    sleep(sleep_after_find)
                    element.click()
                    return True

            except ElementDoesNotExist:
                pass

            sleep(1)

        raise ElementDoesNotExist(css)
示例#6
0
 def find_lig_row(self, lig_name, step):
     """Returns the row element page corresponding to the given uploaded
     ligand basename"""
     selectors = {
         'molpacking': lambda: self.browser.find_by_css(".ligand_list table tr:not(:first-child) td:nth-child(2)"),
         'solvent options': lambda: self.browser.find_by_text("Ligand ID").find_by_xpath('../..').find_by_css("tr:not(:first-child) td:nth-child(2)") 
     }
     rows = selectors[step]()
     found = False
     for row in rows:
         if row.text == lig_name:
             found = True
             break
     if  not found:
         raise ElementDoesNotExist("Could not find ligand: " + lig_name) 
     lig_row = row.find_by_xpath('..')
     return lig_row    
示例#7
0
    def fill_form(self,
                  field_values,
                  form_id=None,
                  name=None,
                  ignore_missing=False):
        form = None

        if name is not None:
            form = self.find_by_name(name)
        if form_id is not None:
            form = self.find_by_id(form_id)

        for name, value in field_values.items():
            try:
                if form:
                    element = form.find_by_name(name)
                    control = element.first._element
                else:
                    element = self.find_by_name(name)
                    control = element.first._control
                control_type = control.get("type")
                if control_type == "checkbox":
                    if value:
                        control.value = value  # control.options
                    else:
                        control.value = []
                elif control_type == "radio":
                    control.value = (
                        value
                    )  # [option for option in control.options if option == value]
                elif control_type == "select":
                    if isinstance(value, list):
                        control.value = value
                    else:
                        control.value = [value]
                else:
                    # text, textarea, password, tel
                    control.value = value
            except ElementDoesNotExist as e:
                if not ignore_missing:
                    raise ElementDoesNotExist(e)
示例#8
0
    def fill_form(self,
                  field_values,
                  form_id=None,
                  name=None,
                  ignore_missing=False):
        form = None

        if name is not None:
            form = self.find_by_name(name)
        if form_id is not None:
            form = self.find_by_id(form_id)

        for name, value in field_values.items():
            try:
                if form:
                    elements = form.find_by_name(name)
                else:
                    elements = self.find_by_name(name)
                element = elements.first
                if (element["type"] in ["text", "password", "tel"]
                        or element.tag_name == "textarea"):
                    element.value = value
                elif element["type"] == "checkbox":
                    if value:
                        element.check()
                    else:
                        element.uncheck()
                elif element["type"] == "radio":
                    for field in elements:
                        if field.value == value:
                            field.click()
                elif element._element.tag_name == "select":
                    element.select(value)
                else:
                    element.value = value
            except ElementDoesNotExist as e:
                if not ignore_missing:
                    raise ElementDoesNotExist(e)
示例#9
0
 def __getitem__(self, index):
     try:
         return super(ElementList, self).__getitem__(index)
     except IndexError:
         raise ElementDoesNotExist('element does not exist')