GCuser99 / SeleniumVBA

A comprehensive Selenium wrapper for browser automation developed for MS Office VBA running in Windows
MIT License
89 stars 18 forks source link

Additional support for IE mode in Edge #9

Closed yaju closed 2 years ago

yaju commented 2 years ago

Reference site http://blog.livedoor.jp/tarboh_w-inko/archives/37451016.html Below the blog post is a link to the modified book. seleniumvba_v1.2_EdgeIEMode.xlsm

Below are additional fixes

Capabilities.cls

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(Application.OperatingSystem, "64-bit") 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

If you do not set the IgnoreZoomLevel property to true, you will get an exception message. image

The reason for this exception error is that IE does not match the coordinate position when clicking unless Zoom is set to 100%. However, in IE mode, setting the IgnoreZoomLevel property to true ignores the exception and Zoom is displayed at 100%.

TinySelenium issue https://github.com/uezo/TinySeleniumVBA/issues/70

GCuser99 commented 2 years ago

Ok I'll look into adding Edge IE mode. Thank you.

One thing that I noticed immediately is that the command "Shutdown" does not consistently shutdown the IE driver on my machine/setup.

For example, after adding the ignoreZoomSetting browser option that you shared above, then running the following test sub, the command window sometimes closes on its own, and other times I have to close it manually. That behavior will have to be debugged and fixed before this can be implemented successfully.

Sub test()
    Dim driver As New WebDriver
    driver.AppWinStyle = vbNormalFocus
    driver.StartIE
    driver.OpenBrowser
    driver.CloseBrowser
    driver.Shutdown
End Sub
GCuser99 commented 2 years ago

Further info... I can get the above subroutine "test" to work consistently if I set the capabilities IE option "initialBrowserUrl" to a correct url like "https://www.google.com/". I cannot explain why that solves (or hides?) the problem, but it seems to work on my computer.

yaju commented 2 years ago

It may be a problem close to the following site https://github.com/SeleniumHQ/selenium/issues/10545

Will it be ShutDown normally if I add NavigateTo?

Sub test()
    Dim driver As New WebDriver
    driver.AppWinStyle = vbNormalFocus
    driver.StartIE
    driver.OpenBrowser
    driver.NavigateTo "https://www.google.com/"
    driver.CloseBrowser
    driver.Shutdown
End Sub
GCuser99 commented 2 years ago

Setting "initialBrowserUrl" does not solve problem - it's so intermittent that it's difficult to tell what is helping or not.

I isolated the problem to executing the "CMD_QUIT" command in CloseBrowser method. The http send request often hangs using the IEDriverServer on my system.

I will try a different computer/setup next...

GCuser99 commented 2 years ago

Tested on a Windows 11 machine (previous was Windows 10), and experienced same intermittent problem with CloseBrowser. The test sub worked about 10 times in a row and then started hanging....

@yaju - what OS and Office version are you using? Thx!

yaju commented 2 years ago

My PC environment

Windows 10 Pro 21H1 Excel for Microsoft 365(32bit) I moved it 10 times in a row. The 10th time, it hung in CloseBrowser.

Another case. Fixed 64bit detect in capabilities.cls.

capabilities.cls

InitializeFor
    Case "internet explorer"
        InStr(Application.OperatingSystem, "64-bit") 
        ↓
        InStr(GetObject("winmgmts:Win32_OperatingSystem=@").OSArchitecture, "64")
GCuser99 commented 2 years ago

@yaju, this problem may be same as this reported issue.

I'll see if I can come up with a temp work-around to recover gracefully from the "hang".

Would you mind providing a usage-case for needing to run Edge in IE mode?

Thanks for your help!

yaju commented 2 years ago

Would you mind providing a usage-case for needing to run Edge in IE mode?

A small RAP that runs regularly once a day

GCuser99 commented 2 years ago

@yaju what is a RAP and why can't it be performed with Edge or Chrome? Why is IE mode in Edge important? Thx!

yaju commented 2 years ago

RAP Typographical error RAP->RPA Tool

There are in-house groupware that are not yet compatible with Edge. For example, some sites are using Active X or are not displayed correctly in Edge.

GCuser99 commented 2 years ago

Got it - thanks for the explanation!

GCuser99 commented 2 years ago

Soon I'll create a develop version branch that will accommodate IE mode...

GCuser99 commented 2 years ago

@yaju, can you tell me why you changed the 64-bit detect method for OS?

InitializeFor
    Case "internet explorer"
        InStr(Application.OperatingSystem, "64-bit") 
        ↓
        InStr(GetObject("winmgmts:Win32_OperatingSystem=@").OSArchitecture, "64")
yaju commented 2 years ago

Windows 10 Pro 21H1(64bit) Excel for Microsoft 365(32bit)

"Application.OperatingSystem" is installed to get Office bits. return 32-bit. But I need is to get Windows OS bit.

GCuser99 commented 2 years ago

Ok @yaju, does this work for you?

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

I'm close to publishing a limited but functional version with IE mode support. I just need to finish documenting the limitations.

yaju commented 2 years ago

@GCuser99

does this work for you?

Test OK

GCuser99 commented 2 years ago

@yaju, with regard to IE mode support, I have created a new discussion here and so will close this issue out. Thanks for your help in getting started!

PS: While your solution above is a good one, I ended up using the native method GetDriverStatus to extract windows and driver architecture (bit-ness). :-)