Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Method. Execute #25

Open
ghost opened this issue Sep 18, 2021 · 4 comments
Open

Modify Method. Execute #25

ghost opened this issue Sep 18, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Sep 18, 2021

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 ghost changed the title Method. Execute Modify Method. Execute Oct 23, 2021
@uezo
Copy link
Owner

uezo commented Dec 30, 2021

@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を削除するのは、このコマンドが特定のセッションではなくすべてのセッションに対して適用されるものだからでしょうか?

@ghost
Copy link
Author

ghost commented Dec 31, 2021

@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)",・・・・・

@GCuser99
Copy link

GCuser99 commented Dec 31, 2021

I think I found the problem and posted solution here

@ghost
Copy link
Author

ghost commented Jan 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants