I'm accessing this url (https://cissearch.kcc.gov.tw/System/Bulletin/View.aspx?BulletinSN=239928&pages=9957#pdfStart) with selenium in python, and I'm trying to click on the download button in the pdfviewer.
I've tried adding options as suggested here: Selenium Webdriver: How to Download a PDF File with Python?
But I end up with a page with an open
button that I still have to manually click to download the pdf file.
I've also tried this route https://www.lambdatest.com/blog/shadow-dom-in-selenium but I was unable to locate any element.
So I'm trying to click on the button with this:
driver.execute_script("document.querySelector('pdf-viewer').shadowRoot.querySelector('viewer-toolbar').shadowRoot.querySelector('viewer-download-controls').shadowRoot.querySelector('cr-action-menu').querySelector('button')")
This javascript works in the devtools console as shown in this image:
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)