'Managing frames and shadow-roots in Python webscraping with Selenium chrome driver [duplicate]

I'm trying to click on the download button in a pdf-viewer page. The button is under multiple shadow roots. Before even getting to the nested button, however, I'm having troubles with locating the right frame (I don't see any frame name in the source code). How do I find it only using Python?

If I get to solve the above error, this would be my code for clicking the button:

non_shadow_root0 = driver.find_element(By.CSS_SELECTOR, 'body')
shadow_host1 = driver.find_element(By.CSS_SELECTOR, '#viewer')
shadow_root1 = shadow_host1.shadow_root
shadow_host2 = shadow_root1.find_element(By.CSS_SELECTOR, '#toolbar')
shadow_root2 = shadow_host2.shadow_root
non_shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, '#toolbar')
non_shadow_root4 = non_shadow_root3.find_element(By.CSS_SELECTOR, '#end')
shadow_host5 = non_shadow_root4.find_element(By.CSS_SELECTOR, '#downloads')
shadow_root5 = shadow_host5.shadow_root
shadow_host6 = shadow_root5.find_element(By.CSS_SELECTOR, '#download')
shadow_root6 = shadow_host6.shadow_root
non_shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, '#icon')
download = non_shadow_root7.click()

Does it look right?

Thanks to anyone who tries to help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source