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: try: 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: pass 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.