Home > Software engineering >  How to click a pdfviewer download button in shadowroot(open) with selenium Python
How to click a pdfviewer download button in shadowroot(open) with selenium Python

Time:01-22

I'm accessing this url (enter image description here

but it returns this error when I run it in python

JavascriptException: Message: javascript error: Cannot read properties of null (reading 'shadowRoot')
  (Session info: chrome=109.0.5414.87)

CodePudding user response:

The issue is that the url does not actually point to a pdf file. It's a webpage with an embedded pdf viewer.

By running this I was able to get the actual url to the pdf file:

pdf_url = driver.find_element_by_tag_name('iframe').get_attribute("src")

and then I can just download it with this

import urllib.request
urllib.request.urlretrieve(pdf_url, "test.pdf")
  • Related