Selenium Shadow-Root / PDF-Viewer accessing Download Button

92 views Asked by At

I've provided a link to the image for reference that will hopefully clear up any questions regarding my issue.

https://drive.google.com/file/d/1tc_0pnvG7SJ8uu6Fv1GfeHM3zOPTVzn8/view?usp=sharing

I can't seem to find a way to access the shadow-root DOM to be able to click the download button.

I'm attempting to download the PDF so I can verify that the PDF is filled out correctly based on the answers provided.

I'm using Python Selenium

The PDF Viewer is a modal that has an embedded shadow-root DOM that has the download button. Once I can access the shadow-root, I know how to download the file.

Any assistance would be greatly appreciated!

I've already attempted to use the API to get the encoded response, then I've decoded it and created a PDF file, however, because I don't format it the way the viewer does, being able to check the information is way too complex. I've manually downloaded the PDF file and already have the verification tests completed, so it's just a matter of being able to download the file now.

My current testing code:

    login_page.click_login()
    main_page.click_application_tab()
    main_page.enter_search(context.caseId)
    application_page.click_action_button()
    application_page.click_view_pdf()

    # This is the part where I am stuck - being able to access the shadow DOM and click the download button

    context.driver.quit()

Here's some code I've attempted:

# download_pdf_button = self.driver.find_element(By.XPATH, '//*[@id="viewer"]').getShadowRoot()\
# .find_element(By.CSS_SELECTOR, 'viewer-toolbar#toolbar').getShadowRoot()\
# .find_element(By.CSS_SELECTOR, 'view-download-controls#downloads')\
# .find_element(By.ID, 'download')

-------------------------------------------------------------------------

# shadow_host = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '[id="viewer"]')))
# shadow_root = shadow_host.shadow_root
# download_pdf_button = wait.until(lambda driver: shadow_root.find_element(By.CSS_SELECTOR, '[id="download"]'))
# download_pdf_button.click()

-------------------------------------------------------------------------
# shadow_root = self.driver.find_element(By.CSS_SELECTOR, '[id="viewer"]').shadow_root
# viewer_toolbar = shadow_root.find_element(By.CSS_SELECTOR, 'viewer-toolbar#toolbar').shadow_root
# view_download_controls = viewer_toolbar.find_element(By.CSS_SELECTOR, 'view-download-controls#downloads')
# download_pdf_button = view_download_controls.find_element(By.CSS_SELECTOR, '[id="download"]')
# download_pdf_button.click()

-------------------------------------------------------------------------
# self.driver.execute_script("""
# const shadowHost = document.querySelector('#viewer');
# const shadowRoot = shadowHost.shadowRoot;
# const downloadButton = shadowRoot.querySelector('#download');
# downloadButton.click();
# """)

I've also checked for multiple window handles and I couldn't see any other windows beside the main one.

0

There are 0 answers