uezo / TinySeleniumVBA

A tiny Selenium wrapper written in pure VBA
MIT License
60 stars 16 forks source link

Add Mrthod. GetWindowRect, SetWindowRect, GetWindowSize, SetWindowSize, GetWindowPosition, SetWindowPosition, MaximizeWindow, FullScreenWindow, MinimizeWindow #32

Open ghost opened 2 years ago

ghost commented 2 years ago

TinySeleniumVBA WebDriver.cls

GetWindowRect:カレントウィンドウのPosition, Sizeを取得する。 x, y, width, height ( px ) SetWindowRect:カレントウィンドウのPosition, Sizeを設定する。 x, y, width, height ( px ) GetWindowSize:カレントウィンドウのSizeを取得する。 width, height ( px ) SetWindowSize:カレントウィンドウのSizeを設定する。 width, height ( px ) GetWindowPosition:カレントウィンドウのPositionを取得する。 x, y ( px ) SetWindowPosition:カレントウィンドウのPositionを設定する。 x, y ( px ) MaximizeWindow:カレントウィンドウを最大にする。 FullScreenWindow:カレントウィンドウをフルスクリーンにする。 MinimizeWindow:カレントウィンドウを最小にする。

' Get Window Rect (px)          '2021/6/24 add ishi
Public Function GetWindowRect(Optional ByVal sessionId As String = vbNullString) As Integer()
    Dim Data    As New Dictionary
    If sessionId <> vbNullString Then
        Data.Add "sessionId", sessionId
    End If

    Dim rects
    Set rects = Execute(CMD_GET_WINDOW_RECT, Data)

    ' To array of rects
    Dim ret()   As Integer
    ReDim Preserve ret(rects.Count - 1)
    ret(0) = CInt(rects.Item("x"))
    ret(1) = CInt(rects.Item("y"))
    ret(2) = CInt(rects.Item("width"))
    ret(3) = CInt(rects.Item("height"))

    ' Return rects
    GetWindowRect = ret
End Function

' Set Window Rect (px)          '2021/6/24 add ishi
Public Function SetWindowRect(Optional ByVal x As Integer = 0, _
                              Optional ByVal y As Integer = 0, _
                              Optional ByVal width As Integer = 0, _
                              Optional ByVal height As Integer = 0, _
                              Optional ByVal sessionId As String = vbNullString) As Integer()
    Dim Data    As New Dictionary
    Data.Add "x", x
    Data.Add "y", y
    Data.Add "width", width
    Data.Add "height", height
    If sessionId <> vbNullString Then
        Data.Add "sessionId", sessionId
    End If

    Dim rects
    Set rects = Execute(CMD_SET_WINDOW_RECT, Data)

    ' To array of rects
    Dim ret()   As Integer
    ReDim Preserve ret(rects.Count - 1)
    ret(0) = CInt(rects.Item("x"))
    ret(1) = CInt(rects.Item("y"))
    ret(2) = CInt(rects.Item("width"))
    ret(3) = CInt(rects.Item("height"))

    ' Return rects
    SetWindowRect = ret
End Function

' Get Window Size (px)          '2021/7/10 add ishi
Public Function GetWindowSize(Optional ByVal sessionId As String = vbNullString) As Integer()
    Dim rect()  As Integer
    rect = GetWindowRect(sessionId)

    Dim ret(1)   As Integer
    ret(0) = rect(2)    'width
    ret(1) = rect(3)    'height

    ' Return
    GetWindowSize = ret
End Function

' Set Window Size (px)          '2021/7/10 add ishi
Public Function SetWindowSize(ByVal width As Variant, _
                              ByVal height As Variant, _
                              Optional ByVal sessionId As String = vbNullString)
    Dim rect()  As Integer
    rect = GetWindowRect
    rect = SetWindowRect(rect(0), rect(1), width, height, sessionId)
End Function

' Get Window Position (px)      '2021/7/10 add ishi
Public Function GetWindowPosition(Optional ByVal sessionId As String = vbNullString) As Integer()
    Dim rect()  As Integer
    rect = GetWindowRect(sessionId)

    Dim ret(1)   As Integer
    ret(0) = rect(0)    'x
    ret(1) = rect(1)    'y

    ' Return
    GetWindowPosition = ret
End Function

' Set Window Position (px)      '2021/7/10 add ishi
Public Function SetWindowPosition(ByVal x As Variant, _
                                  ByVal y As Variant, _
                                  Optional ByVal sessionId As String = vbNullString)
    Dim rect()  As Integer
    rect = GetWindowRect
    rect = SetWindowRect(x, y, rect(2), rect(3), sessionId)
End Function

' Maximize Window               '2021/7/14 add ishi
Public Sub MaximizeWindow(Optional ByVal sessionId As String = vbNullString)
    Dim Data As New Dictionary
    If sessionId <> vbNullString Then
        Data.Add "sessionId", sessionId
    End If

    Execute CMD_W3C_MAXIMIZE_WINDOW, Data
End Sub

' FullScreen Window             '2021/7/14 add ishi
Public Sub FullScreenWindow(Optional ByVal sessionId As String = vbNullString)
    Dim Data As New Dictionary
    If sessionId <> vbNullString Then
        Data.Add "sessionId", sessionId
    End If

    Execute CMD_FULLSCREEN_WINDOW, Data
End Sub

' Minimize Window               '2021/7/14 add ishi
Public Sub MinimizeWindow(Optional ByVal sessionId As String = vbNullString)
    Dim Data As New Dictionary
    If sessionId <> vbNullString Then
        Data.Add "sessionId", sessionId
    End If

    Execute CMD_MINIMIZE_WINDOW, Data
End Sub