webdriver 解决shadow-root获取chrome下载项
2021-03-10 03:29
标签:arguments exe element driver cond dsl class self ado webdriver 解决shadow-root获取chrome下载项 标签:arguments exe element driver cond dsl class self ado 原文地址:https://www.cnblogs.com/bowanghou/p/12859810.html 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}
上一篇:vue.js(2)
文章标题:webdriver 解决shadow-root获取chrome下载项
文章链接:http://soscw.com/index.php/essay/62581.html