def listbox_select_item(desktop_session: WebDriver, listbox: WebElement, item_text: str): """ To find the element in listbox and click on it """ found = False down_btn = try_find_element(listbox, FindElementBy.AUTOMATION_ID, "DownButton", small_retry, ignore_if_not_found=True) while not found: da_instances = listbox.find_elements_by_xpath(".//*") for item in da_instances: logger.info("item.tag_name: " + item.tag_name) logger.info("item.text.lower(): " + item.text.lower()) if item.tag_name == 'ControlType.ListItem' and \ item.text.lower() == item_text.lower(): found = True click_hold(desktop_session, item) while not item.is_selected(): if down_btn is not None: down_btn.click() click_hold(desktop_session, item) else: raise Exception(f"Element: {down_btn} not found") return found
def get_video_time(cls, article: WebElement): cls.set_implicitly_wait(1) _list = article.find_elements_by_xpath('//*[contains(@text, ":")]') cls.set_implicitly_wait(6) if _list: return _list[0].get_attribute('text') else: return None
def is_article(cls, article: WebElement): cls.set_implicitly_wait(0.2) # 文章需要有日期 _date = article.find_elements_by_xpath('//*[starts-with(@text,"2019-")]') if len(_date) == 0: cls.set_implicitly_wait(6) return False # 文章不应该有播放时间 _time = article.find_elements_by_xpath('//*[contains(@text, ":")]') if len(_time) != 0: cls.set_implicitly_wait(6) return False # # 文章不应该有播放进度条 # _seek = article.find_elements_by_class_name('android.widget.SeekBar') # if len(_seek) != 0: return False # 文章不包含专题两个字 _special = article.find_elements_by_xpath('//*[contains(@text, "专题")]') if len(_special) != 0: cls.set_implicitly_wait(6) return False # TODO: 需要更优雅地实现设置隐式等待时间 cls.set_implicitly_wait(6) return True