def fn(element: Element): element.execute_script( """return (function(element, text) { var maxlength = element.getAttribute('maxlength') === null ? -1 : parseInt(element.getAttribute('maxlength')); element.value = maxlength === -1 ? text : text.length <= maxlength ? text : text.substring(0, maxlength); return null; })(arguments[0], arguments[1]);""", str(value))
def get_combo_by_label(self, label: str, parent_base: Element = None): if parent_base: return parent_base.s(f"./descendant::*[text()='{label}']/following-sibling::div/div") else: return s(f"//*[text()='{label}']/following-sibling::div/div")
def get_input_by_label(self, label: str, parent_base: Element = None): if parent_base: label_elem = parent_base.s(f"./descendant::*[text()='{label}']") else: label_elem = self.get_elem_by_text(label) return label_elem.s("./ancestor::div[1]/descendant::input")
def fn(entity: Element) -> None: size = len(browser.all("#todo-list>li")) produced_enough = size >= number if not produced_enough: entity.type('one more').press_enter() raise AssertionError(f'actual produced todos were: {size}')