TinySeleniumVBA icon indicating copy to clipboard operation
TinySeleniumVBA copied to clipboard

Modify Method. Execute

Open ghost opened this issue 4 years ago • 4 comments
trafficstars

TinySeleniumVBA WebDriver.cls

Timeout系のCMDを通すために、CMDのPathにtimeoutがある場合、sessionIDを削除する必要がありました。 下記の Execute は、その処置を加えたものです。 TinySeleniumVBA v0.1.0 or v0.1.1 の WebDriver.cls の Execute関数を置き換えて下さい。

' Execute driver command
Public Function Execute(driverCommand, _
                        Optional parameters As Dictionary = Nothing)
    Dim method As String: method = driverCommand(0)
    Dim path As String: path = driverCommand(1)
    If parameters Is Nothing Then
        Set parameters = New Dictionary
    End If
    
    ' Set default session id if session id is missing
    If Not parameters.Exists("sessionId") Then
        parameters.Add "sessionId", DefaultSessionId
    End If
    
    ' Set params to path
    Dim paramKey As Variant
    For Each paramKey In parameters
        If VarType(parameters(paramKey)) = vbString Then
            path = Replace(path, "$" + paramKey, parameters(paramKey))
        End If
    Next
    
    ' Remove sessionID, if timeouts in path     '2021/7/14 chg ishi
    If InStr(path, "timeouts") > 0 Then
        If parameters.Exists("sessionId") Then
            parameters.Remove "sessionId"
        End If
    End If

    ' Send request to selenium server
    Dim resp As Dictionary
    Set resp = SendRequest(method, UrlBase + path, parameters)
    
    ' Return value(s)
    If IsNull(resp("value")) Then
        Set Execute = New Dictionary
    ElseIf TypeName(resp("value")) = "Collection" Then
        Set Execute = resp("value")
    ElseIf VarType(resp("value")) = vbObject Then
        If resp("value").Exists("error") Then
            Err.Raise 513, "WebDriver.Execute", JsonConverter.ConvertToJson(resp("value"))
        Else
            Set Execute = resp("value")
        End If
    Else
        Execute = resp("value")
    End If
End Function

ghost avatar Sep 18 '21 00:09 ghost

@ezagdd Thank you! Will you let me know the reason for removing the sessionId? I guess this is because this command will be applied to all sessions, not to the specific session, right?

ありがとうございます。sessionIdを削除するのは、このコマンドが特定のセッションではなくすべてのセッションに対して適用されるものだからでしょうか?

uezo avatar Dec 30 '21 03:12 uezo

@uezo sessionIdを削除しない場合、CMD_GET_TIMEOUTSは通りますが、CMD_SET_TIMEOUTSはエラーとなります。 その為、Execute関数内で path に timeouts がある場合に、sessionID を削除しました。 もしかするとコマンドの使い方が誤っているのかもしれません。

実行時エラー '513': "error":"invalid argument","message":"invalid argument: value must be a non-negative integer\r\n (Session info: chrome=96.0.4664.110)",・・・・・

ghost avatar Dec 31 '21 05:12 ghost

I think I found the problem and posted solution here

GCuser99 avatar Dec 31 '21 16:12 GCuser99

GCuser99 ありがとうございます。私も CMD_SET_TIMEOUTS が正常に動作することを確認できました。

ghost avatar Jan 01 '22 02:01 ghost