0

I have a script I've put together which a) creates an InternetExplorer object, b) navigates to a web-based interface for our in-house scheduling system, c) enters a password and selects appropriate view options. The basics of the script are as follows:

Const READYSTATE_COMPLETE = 4

Dim objExplorer
Set objExplorer = Wscript.CreateObject("InternetExplorer.Application", "objExplorer_")

objExplorer.navigate "http://url.to.scheduling.page"

While objExplorer.busy Or objExplorer.ReadyState <> READYSTATE_COMPLETE
    Wscript.Sleep 50
Wend 

Dim objElem
Set objElem = objExplorer.document.getElementById("password")
objElem.value = "password"

Set objElem = Nothing

objExplorer.document.getElementById("commit").Click() 

While objExplorer.busy Or objExplorer.ReadyState <> READYSTATE_COMPLETE
    Wscript.Sleep 50
Wend 

I've been doing some testing w/ IE8 and IE9, and have found that when I script the IE object, the page HTML gets rendered incorrectly (in particular, some text is bolded/italicized). If, however, I launch IE8 or IE9 manually (not via script), the page renders properly. See below for screenshots:

IE RENDERING - MANUAL LAUNCH enter image description here

SCRIPTED IE RENDERING (text bolded and italicized) enter image description here

I initially suspected that this has something to do with the IE document/browser mode getting a different default value in a scripted IE object, but the HTML being rendered has a <!-- DOCTYPE html --> declaration and (at least according to IE dev. tools), both versions are being displayed in standards mode.

Does anyone have any experience with a scripted, post-IE7 IE object rendering pages differently than a manually-launched counterpart? Would scripted and manually-launched objects report themselves in any different way (perhaps to a js function that's browser-sniffing and generating CSS on the fly?)

Any ideas appreciated.

Felix Yan
  • 14,841
  • 7
  • 48
  • 61
  • Does [this SO question](http://stackoverflow.com/questions/4097593/how-to-put-the-webbrowser-control-into-ie9-into-standards) help? I'm not sure if that WebBrowser control is the same as InternetExplorer.Application. – Cheran Shunmugavel Feb 02 '12 at 07:54
  • Thanks for the link, Cheran. I'll take a look, and I can try playing with registry entries, but from what I've seen (and from what this post implies) the IE object called from vbscript should be identical to a "regular" IE object. Also, since the script just calls an instance of iexplore.exe, I don't really have a separate application I can target. But, it's something to play around with! :-) – Greg Williams Feb 03 '12 at 18:27
  • And I had found the `` technique, but unfortunately, the HTML gets generated on-the-fly by a 3rd-party binary app, so I don't have any way to add the meta tag to the HTML output (other than asking the developer to add it). Maybe I'll see if they're willing to give it a try (they're pretty responsive to requests). – Greg Williams Feb 03 '12 at 18:32

1 Answers1

0

IE9 contains both 32 and 64 bit versions (see http://support.microsoft.com/kb/896457). The method of using Wscript.CreateObject("InternetExplorer.Application" will open the 64-bit version of IE9 which has issues with Flash Player, .Net Security, and others.

To see if the 32-bit version gives the same rendering differences, compare how the URLs appear when using iexplore.exe directly from the following locations:

C:\Program Files\Internet Explorer (64-bit)

C:\Program Files (x86)\Internet Explorer (32-bit)

If the IE9 32-bit mode appears correctly, include the following sub-routine in the script and call it as the first line of the script.

Sub Force32bit()
    If InStr(UCase(WScript.FullName), "SYSTEM32") > 0 and CreateObject("Scripting.FileSystemObject").FolderExists("C:\Windows\SysWOW64") Then 
        Dim objShell : Set objShell = CreateObject("WScript.Shell") 
        objShell.CurrentDirectory = "C:\Windows\SysWOW64" 
        objShell.Run "wscript.exe " & WScript.ScriptFullName,1,False  
        WScript.Quit 
    End If 
End Sub

This determines if the script would use IE9 64-bit by default and if so quits and restarts the script to use IE9 32-bit. This should permit the same script to be used on previous versions of IE as well. (see http://www.visualbasicscript.com/Launching-IE-in-32-bit-mode-from-VBS-script-m80179-p2.aspx for more details.

Community
  • 1
  • 1