def index_of_element_by(condition: CollectionCondition): def index_if_exist(collection: Collection): def matches(indexed_item: Tuple[int, Element]): return indexed_item[1].matching(condition) cached = collection.cached index, _ = next(filter(matches, enumerate(cached))) return index return Query( f'index of element by {condition}', index_if_exist, )
def js_property(name: str) -> Query[Element, str]: def fn(element: Element) -> str: return element().get_property(name) return Query(f'js property {name}', fn)
def css_property(name: str) -> Query[Element, str]: def fn(element: Element) -> str: return element().value_of_css_property(name) return Query(f'css property {name}', fn)
def screenshot(filename: str) -> Query[Element, bool]: def fn(element: Element) -> str: return element().screenshot(filename) return Query(f'screenshot {filename}', fn)
def attribute(name: str) -> Query[Element, str]: def fn(element: Element) -> str: return element().get_attribute(name) return Query(f'attribute {name}', fn)
def tab(index: int) -> Query[Browser, str]: def fn(browser: Browser) -> str: return browser.driver.window_handles[index] return Query(f'tab by index {index}', fn)
def attribute(name: str) -> Query[Element, str]: def fn(element: Element) -> str: return element().get_attribute(name) return Query(f'attribute {name}', fn) inner_html = attribute('innerHTML') outer_html = attribute('outerHTML') value = attribute('value') tag: Query[Element, str] = Query('tag name', lambda element: element().tag_name) text: Query[Element, str] = Query('text', lambda element: element().text) # todo: do we need condition for the following? location_once_scrolled_into_view: Query[Element, Dict[str, int]] = Query( 'location once scrolled into view', lambda element: element().location_once_scrolled_into_view, ) # todo: what to do now with have.size* ? o_O size: Union[Query[Element, Dict[str, Any]], Query[Collection, int]] = Query( 'size', lambda entity: entity().size if isinstance(entity, Element) else len(entity()), )