The Wise Owl logo (an owl and the company name)

Our training courses

Other training resources

Our training venues

Why we are different

Details for geophysguy

geophysguy has participated in the following threads:

Added by geophysguy on 22 Aug 2021 at 23:19

Andrew,
I've watched all of the 57 series of videos several times and have learned a great deal and continue to come back to them when i get stuck, however finding this shadow host is stumping me and I haven't found an answer here or anywhere else on the net. So I thought I might go to the source and ask the guru himself.

Here's what i've tried stepping through(F8) the macro to ensure everything is loaded with Selenium Basic of a google chrome pdf with a shadow dom. I'm after a table that is in the chrome browser window that after my macro runs I have to Ctrl Copy and then run another macro to organize and format the table data as I need it. It's a secure website and the rest of the macro runs fine opening 5 tabs in the browser finding all of the elements I need but I'd like to automate this last repetetive task so I would not have to stop Ctrl C and V the data into excel and run another macro. The HTML is:

<body>
    <pdf-viewer id="viewer"></pdf-viewer> flex
        #shadow-root (open)
          <div id="container"> flex
            <div id="sidenav-container">
            <div id="main">
                <embed id="plugin" type="application/x-google-chrome-pdf" ...>    '<-After this

Dim ShadowHost As Selenium.WebElement
Dim ShadowRoot As Selenium.WebElement

With ch
    Set ShadowHost = .FindElement(FindBy.XPath("/html/body/pdf-viewer"))
    Set ShadowHost = .FindElement(FindBy.Css("#viewer")) 
End With

Both the above tried seperatly give:

Run-Time error 7
NOSuchElementError
Element not found for XPath=/html/body/pdf-viewer
or Css=#viewer

'I tried this and didn't get an error:

    Set ShadowHost = .FindElementByXPath("/html/body/*")
    
'BUT the Locals window says ShadowHost tagname = "embed"
'which is the table I'm after!
'but using devtools find gives:
<pdf-viewer id="viewer"></pdf-viewer> flex == $0 
Then I run the following:
    Set ShadowRoot = .ExecuteScript(Script:="retutn arguments[0].ShadowRoot", arguments:=ShadowHost"))
'and i get:

Run-time error '17':
JavaScriptError
javascript error: Unexpected identifier

'So I tried:
    Set ShadowRoot = .ExecuteScript(Script:="retutn arguments[0].ShadowRoot", arguments:=.FindElementByXPath("/html/body/*")"))
'and got the same error 17

'The element has no other shadow-root above but I can't select anything but body.
'I've tried js ch.querySelector("#viewer")
'and a bunch more but can't get the ShadowHost selected.

'So i thought ok I'll just Ctrl A, Ctrl C, .getclipboard like this:
    Set ShadowHost = .FindElementByTag("body").SendKeys(.keys.Control, "a")
    Set ShadowHost = .FindElementByTag("body").SendKeys(.keys.Control, "c")
    Set dataObj = New MSForms.DataObject
    Debug.Print dataObj.GetFromClipboard
'Gives me Compile error mismatch

'So tried this:
    .FindElementByXPath("/html/body/*").AsTable.ToExcel ShDstMLS_ReCOLORADO.Range("M13")
    
'and got:

Run-Time error "59":
UnexpectedTagNameError
Unrecognized tag name.
Expected=table.tbody
Got=embed
'which is what the local window says the tagname of the WebElement is.

So in conclusion, i have 4 questions:
Why the errors:
7?
17?
Compile error mismatch?
59?
ok 5 questions:
Any ideas as to what's going on and can you help a faithful but frustrated follower?

Thanks for any of the questions you might answer,
geophysguy

PS: There is very little on the net on Ctrl copy and paste, using Action or Actions class (do these 2 classes exist in Selenium Basic?)
or SendKeys for Selenium Basic for VBA, plenty with JS JavaScript C and Python but there's enough differences to make trying to answer
a question on one's own very frustrating. Would love to see a video with the Selenium Basic keyboard commands. Guess this counts as 6 questions.

Thanks again.

Head office

Kingsmoor House

Railway Street

GLOSSOP

SK13 2AA

London

Landmark Offices

99 Bishopsgate

LONDON

EC2M 3XD

Manchester

Holiday Inn

25 Aytoun Street

MANCHESTER

M1 3AE

© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.

End of small page here
Please be aware that our website uses cookies!
I'm OK with this Tell me more ...