Jim
Jim

Reputation: 623

HTA VBScript - IE CreateObject(InternetExplorer.Application) IE.Document.form1 doesn't support property or method

I've done this a few times, however I'm not sure why this time my HTA vbscript is yelling at me about Object doesn't support this property or method IE.Document.form1?

Ignore the Wait IE,2000 subs.

Function server_details(server_name)
    dim returnArray(6)

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "http://website/Default.aspx"
    Wait IE,2000
    With IE.Document.form1
        .txtServerName.value = server_name
        .Button1.click
    End With

    Wait IE,4000

    'get info returned
    With IE.Document.all
        serverOS = .txtOS.value
        serverApp = .txtBusinessApp.value
        serverClass = .txtServerClass.value
        serverHost = .txtHost.value
        serverEnv = .txtSupportEnvironment.value
        serverCheckout = .txtCheckoutStatus.value
    End With

    IE.Quit
    Set IE = Nothing
    returnArray(0) = serverOS
    returnArray(1) = ServerApp
    returnArray(2) = serverClass
    returnArray(3) = serverHost
    returnArray(4) = serverEnv
    returnArray(5) = serverCheckout
    server_details = returnArray
End Function

I have this function in my HTA vbscript as well, and it works fine.

Function subnetDetails(server_ip)
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False
    IE.Navigate "http://otherwebsite/detail.aspx"
    Wait IE,2000
    With IE.Document.aspnetForm
        .[ctl00$_SUMMARY$txtIP].value = server_ip
        .[ctl00$_SUMMARY$btnLoad].click
    End With

    'webscrape for TABLE id="ctl00_SUMMARY_gvSubnets"
    Wait IE,9000
    responseHTML = IE.Document.getElementByID("ctl00_SUMMARY_gvSubnets").outerHTML
    IE.Quit
    Set IE = Nothing

    subnetDetails = responseHTML
End Function

Found that form1 is in an iframe, might be why i can't reference it. Any ideas?

<iframe id="ctl00_ContentPlaceHolder1_I1" bordercolor="White" name="I1" src="CSIS.aspx" style="border-style: none; overflow: auto; height: 2500px; width: 1100px;" frameborder="no" scrolling="no">

<html>
    <head>
        <body>
            <form name="form1" bla bla"


 </iframe>

Upvotes: 1

Views: 17162

Answers (2)

Jim
Jim

Reputation: 623

Ok, so figured it out. The iframe was causing all the trouble. For those with the same error message, try checking the form and elements are not part of a iframe within the Site you are trying to scrape. Work backwords in the site grab the iframe source and put that in your vbscript rather then the one you have.

Best Luck!

Upvotes: 1

peter
peter

Reputation: 42192

It is difficult to ignore your wait sub because probably there lies the cause. You seem to use a fixed amount of time while uou should use something like

Do Until IE.readyState = 4
  Wscript.Sleep 100
Loop

also in case of trouble, better separate your object levels one per line, easier to debug

With IE
  With .document
    With ...

and comment out until it works

These oare general guidelines, if you publish the real URL and your wait sub we could give more straightforward advise.

Upvotes: 0

Related Questions