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

Additional support for IE mode in Edge #70

Open
yaju opened this issue May 27, 2022 · 1 comment
Open

Additional support for IE mode in Edge #70

yaju opened this issue May 27, 2022 · 1 comment

Comments

@yaju
Copy link

yaju commented May 27, 2022

Reference site
http://blog.livedoor.jp/tarboh_w-inko/archives/37451016.html

How to support IE mode in Edge

WebDriver.cls

Add IE method

' Launch 'Internet Explorer Driver
Public Sub IE(ByVal driverPath As String, Optional ByVal driverUrl As String = "http://localhost:5555")
    Start driverPath, driverUrl, "internet explorer"
End Sub

Changed to call InitializeFor method
Set capDict = New Dictionary -> CreateCapabilities().Root

' Open browser
Public Function OpenBrowser(Optional Capabilities As Object = Nothing, Optional desiredCapabilities As Dictionary = Nothing, Optional ByVal useAsDefault As Boolean = True) As String
    Set capDict = CreateCapabilities().Root 'New Dictionary

Capabilities.cls

Add case "internet explorer"

InStr(Application.OperatingSystem, "64-bit")
↓ 5/30 fixed
InStr(GetObject("winmgmts:Win32_OperatingSystem=@").OSArchitecture, "64")

Public Sub InitializeFor(ByVal BrowserName As String, Optional ByVal optionKey As String)
    Case "internet explorer"
            BrowserOptionKey = "se:ieOptions"
            browserOptions.Add "ie.edgechromium", True
            If InStr(GetObject("winmgmts:Win32_OperatingSystem=@").OSArchitecture, "64") Then
                browserOptions.Add "ie.edgepath", "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
            Else
                browserOptions.Add "ie.edgepath", "C:/Program Files/Microsoft/Edge/Application/msedge.exe"
            End If
            browserOptions.Add "ignoreZoomSetting", True
End Sub

' Shortcut initializer for internet explorer
Public Sub InitializeForEdge()
    InitializeFor "internet explorer"
End Sub

JSONConverter

Add Case "<"

Public Function ParseJson(ByVal JsonString As String) As Object
    Case "<"
        Set ParseJson = New Dictionary

IE mode in Edge

Calling Driver.Shutdown gives a ParseJson error
In IE mode in Edge, Output result of client.responseText

<html><head><title>WebDriver</title></head><body><p id='main'>This is the initial start page for the WebDriver server.</p></body></html>

Chrome or Edge

In Chrome or Edge, Output result of client.responseText

{"sessionId":"","status":0,"value":null}

Example

Example,bas

' Start WebDriver (Internet explorer)
Dim Driver As New WebDriver
Driver.IE "C:\Tools\IEDriver_win64\IEDriverServer.exe"
Driver.OpenBrowser
Driver.Navigate "https://www.google.co.jp/?q=cat"
Driver.Shutdown

日本語で補足

IEモードの場合にDriver.Shutdownを実行したらParseJsonエラーが発生しました。
原因としてレスポンス結果で、htmlコードが返っていたから。
JSONConverterを修正したくない場合、別の方法で回避すればいいと思います。

またIEモードの場合、Driver.Shutdownとしてもブラウザまでは閉じませんでした。
ブラウザまでを閉じるなら、ユーザー側でDriver.CloseBrowserが必要となります。

あとIEモードの場合にDriver.Shutdownにしないで連続して動かそうとすると下記エラーが発生します。
"Only one session may be created at a time, and a session already exists."
連続して動かすなら、ユーザー側でDriver.Shutdownを実行してもらうといい。

ZoomLevel

IgnoreZoomLevel プロパティを true に設定しないと例外メッセージが出ます。
image

この例外エラーの理由として、IEはZoomを100%にしないとクリック時等の座標位置が合わなくなるからです。
ただIEモードの場合、IgnoreZoomLevel プロパティを true に設定すれば例外を無視する上に、Zoomが100%で表示されました。

32bit OS

32bit OSの考慮も追加しました。
Microsoft Edge (Chromium) x64 のインストール パスが気になる
https://yamanxworld.blogspot.com/2020/11/microsoft-edge-chromium-x64.html

@yaju
Copy link
Author

yaju commented Jun 3, 2022

Changed Capabilities.cls to use Environ variables

Reference issue
GCuser99/SeleniumVBA#9

Case "internet explorer"
    If InStr(GetObject("winmgmts:Win32_OperatingSystem=@").OSArchitecture, "64") Then
        browserOptions.Add "ie.edgepath", Environ("ProgramFiles(x86)") & "\Microsoft\Edge\Application\msedge.exe"
    Else
        browserOptions.Add "ie.edgepath", Environ("ProgramFiles") & "\Microsoft\Edge\Application\msedge.exe"
    End If

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

No branches or pull requests

1 participant