webdriver 解决shadow-root获取chrome下载项
def _return_element(self, ele): return self.driver.driver.execute_script("return arguments[0].shadowRoot", ele) def verify_dl(self): """ 返回最近一个下载,目前仅支持chrome :return: """ self.driver.execute_script(‘window.open("")‘) win_lst = self.driver.window_handles self.driver.switch_to_window(win_lst[-1]) self.driver.get(‘chrome://downloads‘) first_sd = self._return_element(self.driver.find_element_by_css_selector(‘css=downloads-manager‘)) second_sd = self._return_element(first_sd.find_element_by_css_selector("#downloadsList>downloads-item")) name, dl_url = second_sd.find_element_by_css_selector(‘#details‘).text.split(‘\n‘)[:2] self.driver.close() self.driver.switch_to_window(win_lst[0]) return {‘name‘: name, ‘dl_url‘: dl_url}
相关推荐
王练 2020-07-18
jjddrushi 2020-06-14
Reiki 2020-06-12
curiousL 2020-06-01
jessieHJ 2020-05-17
xiangxiaojun 2020-09-23
letheashura 2020-08-14
xiangxiaojun 2020-06-25
Feastaw 2020-06-18
ELEMENTS爱乐冬雨 2020-06-14
云之高水之远 2020-06-14
chongtianfeiyu 2020-06-12
songerxing 2020-06-11
王练 2020-06-11
tiankele0 2020-06-09
dangai00 2020-06-06
云之高水之远 2020-06-05