添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
英勇无比的石榴  ·  Selenium can not find ...·  16 小时前    · 
乐观的针织衫  ·  Finding web elements ...·  16 小时前    · 
体贴的红金鱼  ·  解决vue element ...·  16 小时前    · 
爱热闹的作业本  ·  Jackson XML ...·  2 天前    · 
含蓄的瀑布  ·  chrome 下 ...·  6 天前    · 
机灵的香槟  ·  国家统计局信息公开·  3 周前    · 
单身的菠萝  ·  C# 使用 Json.NET 解析 ...·  6 月前    · 
星星上的铅笔  ·  内田洋行 内田洋行 ...·  11 月前    · 
+ 1

Selenium can not find element within #shadow-root (open)

StackOverflow link for more info: https://stackoverflow.com/q/63709350/14208817 I was trying to automate the docs downloading process using selenium and python but I came across this problem when trying to click the download button.It is inside the #shadow-root (open) maybe because of that it is not found.I tried many solutions for the problem but none of them is working. CODE: ---------------------------------------------------------------------- iimport sys import time from selenium import webdriver from selenium.webdriver.common.keys import Keys def expand_shadow_element(element): shadow_root = driver.execute_script( 'return arguments[0].shadowRoot', element) return shadow_root docs = sys.argv[1:] if docs == []: docs = ['scrapy'] driver = webdriver.Chrome("/home/samip/chromedriver") driver.get(" https://www.google.com/ ") search_box = driver.find_element_by_xpath( '//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input') search_box.send_keys(f'{docs[0]} readthedocs pdf download') search_box.send_keys(Keys.ENTER) time.sleep(1) source = None driver.find_element_by_xpath('//*[@id="Rzn5id"]/div/a[2]').click() infos = driver.find_elements_by_class_name('rc') for info in infos: check = info.find_element_by_class_name('eFM0qc') print(check.text) if check.text == 'PDF': info.find_element_by_tag_name('h3').click() break except Exception: time.sleep(6) ---------------------------------------------------------------------------- Site: https://buildmedia.readthedocs.org/media/pdf/python-guide/latest/python-guide.pdf While trying to use the above user defined function as suggested in answer to similar question the output is None if the element is body and NoSuchElementException is raised if the element is pdf-viewer and other element within #shadow-root (open). I want to click the download button.

3rd Sep 2020, 3:45 PM
Samip Karki
Samip Karki - avatar
11 Answers