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
44 stars 5 forks source link

Run-time error '13' when assign to collection variable. #11

Closed MitsOmitsaras closed 1 year ago

MitsOmitsaras commented 1 year ago

First of all, this is a great job and thank you. I get a Run-time error '13' Type mismatch at the final line just before the Stop statement.

Here is the code:

Private Sub Kataxorisi_Pliromis(oBrwsr As CDPBrowser)
Dim ele As CDPElement
Dim eleCol As Collection
    Set ele = oBrwsr.getElementByXPath("/html/body/div/div[2]/div/iframe").getIFrame
    oBrwsr.wait
    ele.getElementByID("SupplieridD").value = "12846"
    ele.getElementByID("SupplieridD").fireEvent "onkeypress"
    ele.getElementByID("SupplieridD").fireEvent "onkeyup"
    Set eleCol = ele.getElementByID("dynaLayer").getElementsByQuery("div")
Stop
'...

And I'm posting also a screenshot of the code, error and log together. error13

Edit: This seems to be ralated: Also I can't get the Count of this Collection. Eg this:

Debug.Print getElementByID("dynaLayer").getElementsByQuery("div").Count

throws the same error.

longvh211 commented 1 year ago

@MiitsOmitsaras thank you for raising this. I have uploaded 2.7.2 that has this fixed accordingly.

MitsOmitsaras commented 1 year ago

Thanks for the immediate response. I needed this for looping through the elements of a collection and do some checks. Finally I used a Do Loop instead. But your work is excellent and extremely helpful, so it was a pity something that small not working. That's why I reported it.

longvh211 commented 1 year ago

@MiitsOmitsaras I always appreciate all these helps that point out these little bugs because I may not always have the time to test all my codes completely.

Just an additional note from your code: with the fireEvent method, you can just use "keyup" i/o "onkeyup". The method will auto delete the "on" part anyway. Courtesy of the fireEvent definition.