TinySeleniumVBA icon indicating copy to clipboard operation
TinySeleniumVBA copied to clipboard

Add Keys to a collection of For Each statement

Open yaju opened this issue 3 years ago • 5 comments

Mac対応にあたりDictionaryオブジェクトを「Microsoft Scripting Runtime」の代わりに、VBA-tools/VBA-Dictionary を使用した場合、WebDriver.clsのFor Eachの部分で「実行時エラー 438 オブジェクトは、このプロパティまたはメソッドをサポートしていません」が出ます。

' Run-time error '438': Object doesn't support this property or method
For Each paramKey In parameters

For Each key In dict

Keysを追加して頂ければ、このエラーは回避することが出来ます。

For Each paramKey In parameters.Keys

For Each key In dict.Keys

Keysを付けた状態で、Windows上で「Microsoft Scripting Runtime」を参照していてもエラーにならずに正常動作します。

yaju avatar Apr 23 '22 03:04 yaju

Hi @yaju , thank you for reporting issue.

Sounds great. I'm so excited about resolving this issue makes it compatible with Mac!

uezo avatar Apr 25 '22 13:04 uezo

Hi @yaju ,

I found that to make this run on Mac, we have to replace WebDriver.SendRequest() method that uses CreateObject("MSXML2.ServerXMLHTTP") internally.

Do you have any idea?

Mac対応するにあたり、内部的に CreateObject("MSXML2.ServerXMLHTTP") をしている WebDriver.SendRequest() を改修する必要があるとわかりました。curlを利用するなどいくつかの方法があるようですが、他に良い方法をご存知でしょうか?

uezo avatar Apr 25 '22 14:04 uezo

@uezo

自分のところでは、既にMacでExampleのyomoda sobaは動いています。近いうちに記事を書く予定です。 CreateObject("MSXML2.ServerXMLHTTP") の代わりにVBA-Webを使用していますが、その中身ではcurlを利用しています。 また、MacでShellが動作しない件については既に記事を書いてあります。 出来るか分かりませんが、最終的にはVBA-Webを使わない方向にしたいです。

' Send HTTP request
Private Function SendRequest(method As String, url As String, Optional Data As Dictionary = Nothing) As Dictionary
    Dim client As Object
    Dim Response As WebResponse
    Set client = New WebClient
    If method = "POST" Or method = "PUT" Then
        Set Response = client.PostJson(url, Data)
    Else
        Set Response = client.GetJson(url)
    End If

    Dim json As Object
    Set json = JsonConverter.ParseJson(Response.Content)
    Set SendRequest = json
End Function

yaju avatar Apr 25 '22 15:04 yaju

近いうちに記事を書く予定です。

2022年05月22日に書きました。 【Excel】MacでTinySeleniumVBAを使用したい

yaju avatar Jun 11 '22 09:06 yaju

Hi @yaju , It's looking good to me, thank you so much! I don't think much users want to do web scraping with VBA as you said, however, this will help me to develop features on my Mac.

uezo avatar Jun 11 '22 16:06 uezo