码迷,mamicode.com
首页 > Web开发 > 详细

webdriver 解决shadow-root获取chrome下载项

时间:2020-05-09 20:54:14      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:arguments   exe   element   driver   cond   dsl   class   self   ado   

    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}

 

webdriver 解决shadow-root获取chrome下载项

标签:arguments   exe   element   driver   cond   dsl   class   self   ado   

原文地址:https://www.cnblogs.com/bowanghou/p/12859810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!