1

I am unable to click elements of shadow dom elements.

var propelement = await wdriver.findElement(By.xpath('//*[@id="rptLoadingFrame"]'));
var pdf_url = await propelement.getAttribute('src')
wdriver.get(pdf_url);
//var download1  = await wdriver.findElement(By.xpath('//*[@id="download"]'));
//download1.click();

await wdriver.executeScript("document.querySelector('#viewer').shadowRoot.querySelector('#toolbar').shadowRoot.querySelector('#downloads').shadowRoot.querySelector('#download').shadowRoot.querySelector('#icon').click()");

Getting below error message

JavascriptError: javascript error: Cannot read properties of null (reading 'shadowRoot')

  1. PDF viewer is embedded within iframe and no DOM visible accept <slot> element inside Embed element with #Shadow Root (user-agent)

    enter image description here

  2. When I access SRC mentioned in iframe got below DOM i.e. PDF viewer. I want to click "Download" button to download the PDF.

    enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Hiruthere
  • 109
  • 9
  • Try something like this: https://stackoverflow.com/a/54427220/2851311. I know this is for Python, but you should be able to convert it to Javascript. I have not tried myself, but at least one other person commented on the thread that it worked. – hfontanez Mar 26 '22 at 20:12
  • Below capabilities working fine except **download.default_directory**. 'options.setUserPreferences({'download.default_directory': "C:\\Downloads"});' `options.setUserPreferences({'download.prompt_for_download': false});` `options.setUserPreferences({'download.directory_upgradeoad': true});` `options.setUserPreferences({'plugins.always_open_pdf_externally': true});`. Kindly help in changing path. – Hiruthere Mar 28 '22 at 16:27

0 Answers0