Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intermittent objIE problem 2

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
Hello.

I have a script (which some of you may remember part of the development of) which does a fairly basic test to see if our internet connectivity is up.

Most of the time when I run it it works just fine, but sometimes I get the following error:
[tt]Checks.vbs(650, 5) Microsoft VBScript runtime error: Object required: 'objIE.Document.Body'[/tt]

Line 650 is this line from the main code body below:
Code:
If InStr(objIE.Document.Body.innerHTML, "Internet Explorer cannot display the webpage") > 0 Then
Here's the main code snippet:
Code:
Sub CheckInternet(strTestURL)
    Set objIE = wscript.CreateObject("InternetExplorer.Application","objIE_")
    If Err.Number <> 0 Then
        On Error GoTo 0
        Msg = "IE application not found."
        MsgBox Msg,vbExclamation,strAppDescription
        Wscript.Quit
    End If
    On Error GoTo 0

    objIE.visible = false 'true
    objIE.ToolBar = 0
    objIE.statusbar=false
    objIE.Left = 0
    objIE.Top = 0
    objIE.Width = 1024
    objIE.Height = 768
    objIE.Navigate strTestURL
    Do While objIE.Busy = True
        WScript.Sleep 500
    Loop
    
    WScript.Sleep 500

    If InStr(objIE.Document.Body.innerHTML, "Internet Explorer cannot display the webpage") > 0 Then
        strTempErrorMsg = "  Unable to connect to " & strTestURL & ". Trying "
            strInternetErrorText = strInternetErrorText & strHTMLTab & strHTMLTab & "Unable to connect to " & strTestURL & ".<br>"' & ". Trying " &
        strInternetError=True
    Else
        strInternetError=False
        wscript.echo "  Tested internet connectivity to " & strTestURL & " OK."
        strReport = strReport &_
                    strHTMLTab & "OK<br>"
    End If
    objIE.quit
So the question is, why does the error happen sometimes (I'd estimate it at between about 1 time in 20-30 runtimes)? Or, is there a way to mitigate against it (I thought the [tt]Do While objIE.Busy = True[/tt] loop was for that...)?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Here is the code that I use here to open a Web application that I have had no problems with.

Code:
			Set objIE=WScript.createobject("internetexplorer.application","objIE")
			objIE.visible = True
			objIE.TheaterMode = False  
			objIE.AddressBar = True  
			objIE.StatusBar = False
			objIE.MenuBar = True
			objIE.FullScreen = False 
			[!]objIE.Navigate "about:blank"[/!]
			Do Until objIE.ReadyState = 4
			    WScript.Sleep 100
			Loop 
			objShell.SendKeys "% X" ' Open full screen
			[red]URL = "[URL unfurl="true"]http://"[/URL] & UserComputer & "/CoreDirector_" & strCoreServerVersion &_
			"/login.aspx?BK=" & strBank
			objIE.Navigate(URL)[/red]

The main difference I see with your is that you are opening a "strTestURL" which I cannot account for, but when I tried to open anything before waiting for IE to open the bank page I had trouble with this code.

Thanks

John Fuhrman
Titan Global Services
 
strTestURL = " on the first run, if that comes up with the error then I get the script to try another highly reliable website before finally deciding that internet access is down and performing some other checks.

Anyway, I'll add in that line and the subsequent 'ReadyState' test loop to see if that helps.

Kind of difficult to prove though...

Cheers!

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Let me know if it helps.

Just a curiosity peice though.
objIE.Left = 0
objIE.Top = 0
objIE.Width = 1024
objIE.Height = 768

You are setting location and size of IE when it is not visible??

You can probably omit this.

Thanks

John Fuhrman
Titan Global Services
 
True, I had it in there when I was leaving the window visible to check the code was working.

Have to tell you though that the error still happens occasionally.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
To guard against the sporadic runtime error like:
>Microsoft VBScript runtime error: Object required: 'objIE.Document.Body'
surely, the line in red color is _not_ enough.
> Do While objIE.Busy = True
WScript.Sleep 500
Loop
[red]WScript.Sleep 500[/red]


Do this instead.

[tt] Do While objIE.Busy = True
WScript.Sleep 500
Loop

[red]'[/red]WScript.Sleep 500
[green]do while objIE.Document is nothing
wscript.sleep 50
loop
do while objIE.Document.body is nothing
wscript.sleep 50
loop[/green]
'continue... with the following lines
[/tt]
 
Now I'm back in the office, I'll give that a go, thanks.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top