def test_get_element_by_rimo_id(self): elm = WebElement(tag='a', id='a', rimo_id='b') self.assertIsNone(getElementById('a')) self.assertIsNone(getElementByRimoId('b')) self.doc.appendChild(elm) self.assertIs(getElementById('a'), elm) self.assertIsNone(getElementByRimoId('a')) self.assertIs(getElementByRimoId('b'), elm)
def test_get_element_by_id(self): elm = WdomElement(tag='a', id='a', wdom_id='b') self.assertIs(getElementById('a'), elm) self.assertIs(getElementByWdomId('b'), elm) self.assertIsNone(self.doc.getElementById('a')) self.assertIsNone(self.doc.getElementByWdomId('b'), elm) self.doc.appendChild(elm) self.assertIs(getElementById('a'), elm) self.assertIs(getElementByWdomId('b'), elm) self.assertIs(self.doc.getElementById('a'), elm) self.assertIs(self.doc.getElementByWdomId('b'), elm)
def control(self) -> HTMLElement: id = self.getAttribute('for') if id: if self.ownerDocument: return self.ownerDocument.getElementById(id) else: from wdom.document import getElementById return getElementById(id)
def control(self) -> Optional[HTMLElement]: """Return related HTMLElement object.""" id = self.getAttribute('for') if id: if self.ownerDocument: return self.ownerDocument.getElementById(id) elif isinstance(id, str): from wdom.document import getElementById return getElementById(id) else: raise TypeError('"for" attribute must be string') return None
def __init__(self, *args, form=None, **kwargs): self._form = None super().__init__(*args, **kwargs) from wdom.document import getElementById if isinstance(form, (str, int)): form = getElementById(form) if isinstance(form, HTMLFormElement): self._form = form elif form is not None: raise TypeError( '"form" attribute must be an HTMLFormElement or id of' 'HTMLFormElement in the same document.' )
def __init__(self, *args: Any, form: Union[str, 'HTMLFormElement'] = None, **kwargs: Any) -> None: """``form`` is a ``HTMLFormElement`` object or id of it.""" super().__init__(*args, **kwargs) # type: ignore self.__form = None from wdom.document import getElementById if isinstance(form, str): form = getElementById(form) if isinstance(form, HTMLFormElement): self.__form = form elif form is not None: raise TypeError( '"form" attribute must be an HTMLFormElement or id of' 'HTMLFormElement in the same document.')