def show_desktop(dsk_session: WebDriver): """ Minimize all windows before opening window you need to work on. use to overcome command not working issue due to working window being overlapped by other unwanted window """ dsk_session.find_element_by_class_name( "TrayShowDesktopButtonWClass").click()
def try_find_element(web_driver: WebDriver, by: FindElementBy, unique_val, retry_count, ignore_if_not_found=False) \ -> WebElement: """ attempts to find element within defined retry count. raises NoSuchElementException if ignore_if_not_found=false """ element = None retried = 0 while True: try: if by == FindElementBy.CLASS: element = web_driver.find_element_by_class_name(unique_val) elif by == FindElementBy.NAME: element = web_driver.find_element_by_name(unique_val) elif by == FindElementBy.AUTOMATION_ID: element = web_driver.find_element_by_accessibility_id( unique_val) except NoSuchElementException: retried = retried + 1 if retried > retry_count: if ignore_if_not_found: return None raise NoSuchElementException else: sleep(1) continue break return element