longvh211 / Chromium-Automation-with-CDP-for-VBA

A method to directly automate Chromium-based web browsers, such as Chrome, Edge, and Firefox, using VBA for Office applications by following the Chrome DevTools Protocol framework.
MIT License
45 stars 6 forks source link

Runtime error 91 and Runtime error 901 #25

Open pingme89jp opened 8 months ago

pingme89jp commented 8 months ago

I get a runtime error 91.

The error occurs in the Public Function jsEval on this following line: : Set objMessage = core.jsConverter.ParseJson(strMessage)

I amended the code by addng: `Dim Core As CDPCore Set Core = New CDPCore

The test code I used is: Sub TestBrowser() ' Example of initializing an object Dim Browser As CDPBrowser Set Browser = New CDPBrowser

Dim Core As CDPCore Set Core = New CDPCore

Dim myELE As CDPElement Set myELE = New CDPElement

Dim myJCon As CDPJConv Set myJCon = New CDPJConv

' Start the browser and navigate to a URL
Browser.start [https://www.cnn.com](https://urldefense.com/v3/__https:/www.cnn.com__;!!LSAcJDlP!wnngbSyYmCIOiMr19bdf-WTJV9P6OZGbgl4z5Gi01aviH6KiKetbje-hCQygGBOxPGYJuZX_ht6Uwkgzt91R85Mh7w8$)

' Wait for the page to load completely
Browser.wait

' Find an element by its ID and interact with it
Dim element As CDPElement
Set element = Browser.getElementByID("elementId") ' Replace "elementId" with the actual ID of the element you want to interact with
If Not element Is Nothing Then
    [element.click](https://urldefense.com/v3/__http:/element.click__;!!LSAcJDlP!wnngbSyYmCIOiMr19bdf-WTJV9P6OZGbgl4z5Gi01aviH6KiKetbje-hCQygGBOxPGYJuZX_ht6Uwkgzt91R7DUj0yo$) ' Example interaction: click the element
End If

' Close the browser
Browser.quit

End Sub`

The initial error went away but now I get another error. The error is Run-time error ‘901’: Error PeekNamePipe in readProcCDP

The error occurs in the Public Function readProcCDP. The line of code it gets the error on is: If lngRes = 0 Then Err.Raise 901, Description:="Error PeekNamedPipe in readProcCDP."

WebControl 2.zip

pingme89jp commented 8 months ago

Please note that I use Office 365.

longvh211 commented 8 months ago

Hi Philip, I notice there are various issues in the test code you have provided in the WebControl2.xlsm:

  1. Per definition of v2.7.3, the first argument of CDPBrowser.start is browser name which is either "chrome" or "edge". Yet you are inputting a url link. URL link is supposed to be the second argument but again, this is actually appUrl argument which is meant for firing up a standalone app-like window with the url.
  2. CDPCore class is not meant to be initialized manually. You should never need to initialize it. Same as the CDPJConv class.

Try the working file (v2.7.4 - public latest) below and run the PhilipTest sub procedure in the Demo module and see if it works at your end?

demo_for_philip.xlam.zip

pingme89jp commented 8 months ago

Hi Long,The URL opens now. I have a button I need to click. Pardon my ignorance, when inspecting the element, I can’t find the ElementID. I tried using Xpath but I get an element not found error.This is the element:<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon feather feather-folder-plus">What can I do?Thanks,PhilipOn Mar 6, 2024, at 8:02 AM, Long Vh @.***> wrote: Hi Philip, I notice there are various issues in the test code you have provided in the WebControl2.xlsm:

Per definition of v2.7.3, the first argument of CDPBrowser.start is browser name which is either "chrome" or "edge". Yet you are inputting a url link. URL link is supposed to be the second argument but again, this is actually appUrl argument which is meant for firing up a standalone app-like window with the url. CDPCore class is not meant to be initialized manually. You should never need to initialize it. Same as the CDPJConv class.

Try the working file (v2.7.4 - public latest) below and run the PhilipTest sub procedure in the Demo module and see if it works at your end? demo_for_philip.xlam.zip

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

longvh211 commented 8 months ago

Hi Philip,

Try replacing that element interaction line with this. I basically follow the examples I wrote in the getElementByQuery method's defintion information.

Set element = browser.getElementByQuery("svg[xmlns='http://www.w3.org/2000/svg']")

pingme89jp commented 8 months ago

I could not get the getElementByQuery to work. The area of the webpage I want to interact with is a pane on the right side of the page.

There are 5 clickable areas in that pane. I can’t see anything that distinguishes any of the clickable buttons.

This is the HTML portion of that right pane:

Regards,

Philip

From: Long Vh @.> Sent: Friday, March 8, 2024 8:41 PM To: longvh211/Chromium-Automation-with-CDP-for-VBA @.> Cc: pingme89jp @.>; Author @.> Subject: Re: [longvh211/Chromium-Automation-with-CDP-for-VBA] Runtime error 91 and Runtime error 901 (Issue #25)

Hi Philip,

Try replacing that element interaction line with this. I basically follow the examples I wrote in the getElementByQuery method's defintion information.

Set element = browser.getElementByQuery("svg[xmlns='http://www.w3.org/2000/svg']")

— Reply to this email directly, view it on GitHub https://github.com/longvh211/Chromium-Automation-with-CDP-for-VBA/issues/25#issuecomment-1986682199 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BGVNB7Y6BTAMMESGTTJ6CZTYXJSBZAVCNFSM6AAAAABEGJT7XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWGY4DEMJZHE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/BGVNB77RC2LAYKJZ7SQEFQ3YXJSBZA5CNFSM6AAAAABEGJT7XKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTWNJOVO.gif Message ID: @. @.> >

longvh211 commented 8 months ago

Hi Philip, if you are trying to interact with an element in the W3 schools page, you will have to inspect to see if the element is nested under an iframe (or multiple layers of iframe). I remembered their code demo page usually has two sides, each nested under iframes.

If the element is under an iframe, have a look at some of the demos I wrote in the CDP framework to get an idea how you can interact with it.

pingme89jp commented 8 months ago

The site is my company’s internal CRM page. It is a CRM system that was developed in-house. The W3 schools reference threw me off too. I could not find any references to iframes. But it is clearly a right window pane where the button I want to click is located.I tried saving the page as HTML to review but it ended up being a link, so was not able to do so.PhilipOn Mar 12, 2024, at 8:45 AM, Long Vh @.***> wrote: Hi Philip, if you are trying to interact with an element in the W3 schools page, you will have to inspect to see if the element is nested under an iframe (or multiple layers of iframe). I remembered their code demo page usually has two sides, each nested under iframes. If the element is under an iframe, have a look at some of the demos I wrote in the CDP framework to get an idea how you can interact with it.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

longvh211 commented 8 months ago

You can manually copy the HTML text. Open the Devtools window then right-click on the top html element -> copy -> copy element.

image
pingme89jp commented 8 months ago

Thanks. I really appreciate the help. I was able to use a dummy CRM page for the HTML. Please see the HTML in the attached Word document.

Regards,

Philip

From: Long Vh @.> Sent: Wednesday, March 13, 2024 1:18 AM To: longvh211/Chromium-Automation-with-CDP-for-VBA @.> Cc: pingme89jp @.>; Author @.> Subject: Re: [longvh211/Chromium-Automation-with-CDP-for-VBA] Runtime error 91 and Runtime error 901 (Issue #25)

You can manually copy the HTML text. Open the Devtools window then right-click on the top html element -> copy -> copy element.

image.png (view on web) https://github.com/longvh211/Chromium-Automation-with-CDP-for-VBA/assets/37789938/5f3f0736-ef04-41e9-b3c3-b98b25553de2

— Reply to this email directly, view it on GitHub https://github.com/longvh211/Chromium-Automation-with-CDP-for-VBA/issues/25#issuecomment-1993581069 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BGVNB72XE42MXCME3YPSJNTYX7ORLAVCNFSM6AAAAABEGJT7XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJTGU4DCMBWHE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/BGVNB72NMYF3MIPK5WJRQ5LYX7ORLA5CNFSM6AAAAABEGJT7XKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTW2ORA2.gif Message ID: @. @.> >

longvh211 commented 8 months ago

Hi Philip, the word document does not seem to be attached. Would you be able to paste the entire text somewhere if your company computer is not allowed to upload file to github?

pingme89jp commented 8 months ago

Can you download the file from my Dropbox ? https://www.dropbox.com/scl/fi/7bm4v4vzh2r4p4zrzl225/Test-Pickup.docx?rlkey=heu77vpyawpqnd69za2vci03b&dl=0 [https://www.dropbox.com/temp_thumb_from_token/c/7bm4v4vzh2r4p4zrzl225?preserve_transparency=False&rlkey=heu77vpyawpqnd69za2vci03b&size=1200x1200&size_mode=4]https://www.dropbox.com/scl/fi/7bm4v4vzh2r4p4zrzl225/Test-Pickup.docx?rlkey=heu77vpyawpqnd69za2vci03b&dl=0 Test Pickup.docxhttps://www.dropbox.com/scl/fi/7bm4v4vzh2r4p4zrzl225/Test-Pickup.docx?rlkey=heu77vpyawpqnd69za2vci03b&dl=0 Shared with Dropbox www.dropbox.com


From: Long Vh @.> Sent: Wednesday, March 20, 2024 1:24 AM To: longvh211/Chromium-Automation-with-CDP-for-VBA @.> Cc: pingme89jp @.>; Author @.> Subject: Re: [longvh211/Chromium-Automation-with-CDP-for-VBA] Runtime error 91 and Runtime error 901 (Issue #25)

Hi Philip, the word document does not seem to be attached. Would you be able to paste the entire text somewhere if your company computer is not allowed to upload file to github?

— Reply to this email directly, view it on GitHubhttps://github.com/longvh211/Chromium-Automation-with-CDP-for-VBA/issues/25#issuecomment-2008679659, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BGVNB74BO6Q52VAHAOOPYKLYZEMR7AVCNFSM6AAAAABEGJT7XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBYGY3TSNRVHE. You are receiving this because you authored the thread.Message ID: @.***>