<i id='hnceY'><tr id='hnceY'><dt id='hnceY'><q id='hnceY'><span id='hnceY'><b id='hnceY'><form id='hnceY'><ins id='hnceY'></ins><ul id='hnceY'></ul><sub id='hnceY'></sub></form><legend id='hnceY'></legend><bdo id='hnceY'><pre id='hnceY'><center id='hnceY'></center></pre></bdo></b><th id='hnceY'></th></span></q></dt></tr></i><div id='hnceY'><tfoot id='hnceY'></tfoot><dl id='hnceY'><fieldset id='hnceY'></fieldset></dl></div>
      <bdo id='hnceY'></bdo><ul id='hnceY'></ul>
  • <tfoot id='hnceY'></tfoot>

      <small id='hnceY'></small><noframes id='hnceY'>

      1. <legend id='hnceY'><style id='hnceY'><dir id='hnceY'><q id='hnceY'></q></dir></style></legend>

        Selenium webdriver 在 chrome://downloads 找不到元素

        时间:2023-10-08

            • <legend id='B5nUp'><style id='B5nUp'><dir id='B5nUp'><q id='B5nUp'></q></dir></style></legend>

              <small id='B5nUp'></small><noframes id='B5nUp'>

              1. <tfoot id='B5nUp'></tfoot>
              2. <i id='B5nUp'><tr id='B5nUp'><dt id='B5nUp'><q id='B5nUp'><span id='B5nUp'><b id='B5nUp'><form id='B5nUp'><ins id='B5nUp'></ins><ul id='B5nUp'></ul><sub id='B5nUp'></sub></form><legend id='B5nUp'></legend><bdo id='B5nUp'><pre id='B5nUp'><center id='B5nUp'></center></pre></bdo></b><th id='B5nUp'></th></span></q></dt></tr></i><div id='B5nUp'><tfoot id='B5nUp'></tfoot><dl id='B5nUp'><fieldset id='B5nUp'></fieldset></dl></div>

                  <bdo id='B5nUp'></bdo><ul id='B5nUp'></ul>

                    <tbody id='B5nUp'></tbody>
                  本文介绍了Selenium webdriver 在 chrome://downloads 找不到元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在 python 中使用 selenium 和 chromedriver.

                  I use selenium with the chromedriver in python.

                  我的问题是当我尝试访问 chrome 下载页面 (chrome://downloads) 上的元素时,selenium 给了我一个错误.例如,我尝试获取文件 url "http://file.jpg".

                  My problem is that selenium gives me an error as i try to access elements on the chrome download page (chrome://downloads). For example i try to get the file url "http://file.jpg".

                  <a id="url" target="_blank" href="http://file.jpg">http://file.jpg</a>
                  

                  但是当我尝试通过它的 id 获取元素时,我得到了一个异常.

                  But as i try to get the element by its id I get an exception.

                  代码:

                  driver = webdriver.Chrome("chromedriver.exe")
                  driver.get("chrome://downloads/")
                  file_url = driver.find_element_by_id("url").get_attribute("href")
                  

                  例外:

                  Traceback (most recent call last):
                    File "<pyshell#34>", line 3, in <module>
                      driver.find_element_by_id("url")
                    File "D:Pythonlibsite-packagesseleniumwebdriver
                  emotewebdriver.py", line 269, in find_element_by_id
                      return self.find_element(by=By.ID, value=id_)
                    File "D:Pythonlibsite-packagesseleniumwebdriver
                  emotewebdriver.py", line 752, in find_element
                      'value': value})['value']
                    File "D:Pythonlibsite-packagesseleniumwebdriver
                  emotewebdriver.py", line 236, in execute
                      self.error_handler.check_response(response)
                    File "D:Pythonlibsite-packagesseleniumwebdriver
                  emoteerrorhandler.py", line 192, in check_response
                      raise exception_class(message, screen, stacktrace)
                  selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"url"}
                    (Session info: chrome=56.0.2924.87)
                    (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.10586 x86_64)
                  

                  通过 driver.execute_script() 使用 javascript 对我也不起作用.当我在浏览器中看到元素时,为什么会收到 NoSuchElementException?

                  Using javascript via driver.execute_script() didn't work for me either. Why am i getting a NoSuchElementException when i can see the element in the browser?

                  推荐答案

                  位于多个 shadow-root 块内的目标链接.试试这个:

                  Target link located inside several shadow-root blocks. Try this:

                  driver = webdriver.Chrome("chromedriver.exe")
                  driver.get("chrome://downloads/")
                  
                  manager = driver.find_element_by_css_selector('body/deep/downloads-manager')
                  item = manager.find_element_by_css_selector('body/deep/downloads-item')
                  shadow = driver.execute_script('return arguments[0].shadowRoot;', item)
                  link = shadow.find_element_by_css_selector('div#title-area>a')
                  
                  file_url = link.get_attribute("href")
                  

                  这篇关于Selenium webdriver 在 chrome://downloads 找不到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在启动 Chrome 并尝试使用 Selenium 使用 Chrome 下一篇:Ubuntu:selenium.common.exceptions:未创建会话:此版本的

                  相关文章

                  最新文章

                • <legend id='h4EHS'><style id='h4EHS'><dir id='h4EHS'><q id='h4EHS'></q></dir></style></legend>

                  <small id='h4EHS'></small><noframes id='h4EHS'>

                • <i id='h4EHS'><tr id='h4EHS'><dt id='h4EHS'><q id='h4EHS'><span id='h4EHS'><b id='h4EHS'><form id='h4EHS'><ins id='h4EHS'></ins><ul id='h4EHS'></ul><sub id='h4EHS'></sub></form><legend id='h4EHS'></legend><bdo id='h4EHS'><pre id='h4EHS'><center id='h4EHS'></center></pre></bdo></b><th id='h4EHS'></th></span></q></dt></tr></i><div id='h4EHS'><tfoot id='h4EHS'></tfoot><dl id='h4EHS'><fieldset id='h4EHS'></fieldset></dl></div>

                  1. <tfoot id='h4EHS'></tfoot>
                    • <bdo id='h4EHS'></bdo><ul id='h4EHS'></ul>