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

2021-03-10 03:29

阅读:394

标签: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

上一篇:vue.js(2)

下一篇:Session会话 Cookie JSTL标签


评论


亲,登录后才可以留言!