def is_selected(self, term): """ Returns True if the radio button found matching the term is selected :param term: string or regex :rtype: bool """ found = self.frame.radio(label=term) if found.exists: return found.is_selected raise UnknownObjectException( 'Unable to locate radio matching {}'.format(term))
def radio(self, **kwargs): """ Gets a Radio for the RadioSet :rtype: Radio """ name = self.name if name and ('name' not in kwargs or kwargs.get('name') == name): return self.frame.radio(**dict(kwargs, name=name)) elif not name: return self.source else: raise UnknownObjectException('{} does not match name of RadioSet: ' '{}'.format(kwargs.get('name'), name))
def radios(self, **kwargs): """ Gets a RadioCollection for the RadioSet :rtype: RadioCollection """ name = self.name if name and ('name' not in kwargs or kwargs.get('name') == name): return self._element_call( lambda: self.frame.radios(**dict(kwargs, name=name)), self.source.wait_for_present) elif not name: return RadioCollection(self.frame, {'element': self.source.wd}) else: raise UnknownObjectException('{} does not match name of RadioSet: ' '{}'.format(kwargs.get('name'), name))
def select(self, term): """ Select the radio button whose value or label matches the given string. :param term: string or regex :returns: the value or text of the radio selected :rtype: str """ for key in ['value', 'label']: radio = self.radio(**{key: term}) if radio.exists: if not radio.is_selected: radio.click() return radio.value if key == 'value' else radio.text raise UnknownObjectException( 'Unable to locate radio matching {}'.format(term))
def is_selected(self, term): """ Returns True if any of the selected options' text or label matches the given value :param term: string or regex to match against the option :rtype: bool :raises: UnknownObjectException """ by_text = self.options(text=term) if any(option.is_selected for option in by_text): return True by_label = self.options(label=term) if any(option.is_selected for option in by_label): return True if len(by_text) + len(by_label) != 0: return False raise UnknownObjectException('Unable to locate option matching {}'.format(term))
def select(self, term): """ Select the radio button whose value or label matches the given string. :param term: string or regex :returns: the value or text of the radio selected :rtype: str """ found_by_value = self.radio(value=term) found_by_text = self.radio(label=term) if found_by_value.exists: if not found_by_value.is_selected: found_by_value.click() return found_by_value.value elif found_by_text.exists: if not found_by_text.is_selected: found_by_text.click() return found_by_text.text else: raise UnknownObjectException( 'Unable to locate radio matching {}'.format(term))
def _raise_present(self): raise UnknownObjectException( 'element located, but timed out after {} seconds, waiting ' 'for {} to be present'.format(nerodia.default_timeout, self))