Jump to content
Sign in to follow this  
hispeed_mike

Error Returning Form Name - Need Help !!!

Recommended Posts

hispeed_mike

Hi All,

I have various scripts that automate setup of different network devices via their web interface. Scripted alot of them and cam across a brother printer I need to configure that does not have a form name in the html just an action.Here is my code:

#include <IE.au3> 
#include <inet.au3>

$ip = "10.10.10.100"
$siteid = "Test"
$currentip = "10.10.10.9"
$printname = "Printer"


__HS2170W ($ip, $siteid, $currentip, $printname)

Func __HS2170W($ip, $siteid, $currentip, $printname)
    
        $url = "http://10.10.10.9/bio/general.html?interface=1"

        
        $nav = _IECreate ($url, 0, 1, 0, 1)
        
        WinWait ("Connect to " & $currentip, "")
        ControlSend ("Connect to " & $currentip, "", "Edit2", "admin")
        ControlSend ("Connect to " & $currentip, "", "Edit3", "access")
        ControlClick ("Connect to " & $currentip, "", "Button2")
        
        #cs
        $oDoc = _IEDocGetObj($nav)
        $oArray = $oDoc.getElementsByTagName ("nodename")
        For $element In $oArray
        If $element.id="nodename" Then _IEFormElementSetValue($element, "Found you")
        Next    
        ;_IENavigate ($nav, "http://192.168.1.1/setup.cgi?next_file=Setup.htm")
        #ce
        
        
        $colForms = _IEFormGetCollection ($nav )

        For $oForm In $colForms
            $oFormElements = _IEFormElementGetCollection ( $oForm )
            For $oFormElement In $oFormElements
                If $oFormElement.id = 'nodename' Then 
                    _IEFormElementSetValue ( $oFormElement, "Found You" )
                EndIf
            
                
            Next
        Next
EndFunc

Here is the Webpage Source:

<!-- All Rights Reserved. Copyright(C) 2000-2005 Brother Industries, Ltd.  -->
<HTML>
<HEAD>
<TITLE>Brother HL-2170W series</TITLE>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
 
 
 
<LINK REL=STYLESHEET TYPE="text/css" Href="/printer/printer.css">
 
 
 
 
 
 
</HEAD>
<BODY topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<script LANGUAGE="JavaScript"> 
<!--
var pretext = "";
setTimeout("checkstring()", 250);
function checkstring()
{
var str = document.forms[0].nodename.value;
if (str != pretext){
searchstring(str);
}
str = document.forms[0].nodename.value;
pretext = str;
setTimeout("checkstring()", 100);
}
function searchstring(str)
{
if (str.match(/[^\w|\-|\@|\_]/) || str.match(/[\|]/)){
document.forms[0].nodename.value = pretext;
}
}
//-->
</SCRIPT>
 
<A NAME="top"></A>
<CENTER>
<DIV CLASS="headinfo">
<TABLE height="106" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TBODY>
<TR>
<TD width="20"></TD>
<TD vAlign=top align=left>
<!--// brother logo //-->
<IMG SRC="/pbio/brother.gif" WIDTH="144" HEIGHT="52" BORDER="0">
<BR>
<!--// Model Name //-->
<IMG SRC="/printer/hl2170w.gif" WIDTH="144" HEIGHT="16" BORDER="0">
</TD>
<TD valign=top align=center>
<!--// LINK ITEMS //-->
<TABLE cellSpacing="0" cellPadding="0" border="0">
<TR>
<TD VALIGN="top">
<!--// LEFT ITEMS //-->
<TABLE cellSpacing="2" cellPadding="0" border="0">
<TR>
<TD noWrap CLASS="headtd">
<A HREF="/printer/main.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Home Page
</A>
</TD>
</TR>
<TR>
<TD noWrap CLASS="headtd">
<A HREF="/printer/configu.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">View Configuration
</A>
</TD>
</TR>
<TR>
<TD noWrap CLASS="headtd">
<A HREF="/printer/maininfo.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Maintenance Information
</A>
</TD>
</TR>
<TR>
<TD noWrap CLASS="headtd">
<A HREF="/pbio/find.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Find Device
</A>
</TD>
</TR>
</TABLE>
<!--// END OF LEFT ITEMS //-->
</TD>
<TD>
<!--// RIGHT ITEMS //-->
<TABLE cellSpacing="2" cellPadding="0" border="0">
<TR>
<TD ROWSPAN="1">
<A HREF="/pbio/hlp_certify.html"><IMG 
SRC="/pbio/key_user.gif" WIDTH="24" HEIGHT="11" BORDER="0" ALT="Help" ><BR><IMG 
SRC="/pbio/bar_v.gif" WIDTH="24" HEIGHT="3" BORDER="0" ><BR><IMG 
SRC="/pbio/bar_h.gif" WIDTH="24" HEIGHT="1" BORDER="0" ><BR>
</A>
</TD>
<TD noWrap CLASS="headtd">
<A HREF="/user/prnset.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Printer Settings
</A>
</TD>
</TR>
<TR>
<TD ROWSPAN="3">
<A HREF="/pbio/hlp_certify.html"><IMG 
SRC="/pbio/key_admin.gif" WIDTH="24" HEIGHT="11" BORDER="0" ALT="Help"><BR><IMG 
SRC="/pbio/bar_v.gif" WIDTH="24" HEIGHT="30" BORDER="0" ><BR><IMG 
SRC="/pbio/bar_h.gif" WIDTH="24" HEIGHT="1" BORDER="0" ><BR>
</A>
</TD>
<TD noWrap CLASS="headtd">
<A HREF="/admin/password.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Administrator Settings
</A>
</TD>
</TR>
<TR>
<TD noWrap CLASS="headtd">
<A HREF="/admin/panel.html"CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Reset &amp; Test
</A>
</TD>
</TR>
<TR>
<TD noWrap CLASS="headtd">
<A HREF="/bio/main.html" CLASS="heada">
<img src="/printer/ball.gif" border=0 width="15" height="11">Network Configuration
</A>
</TD>
</TR>
</TABLE>
<!--// RIGHT ITEMS //-->
</TD>
<TD width=20></TD>
<TD>
<A HREF="/pbio/hlp_certify.html"><IMG 
SRC="/printer/key_help.gif" WIDTH="36" HEIGHT="39" BORDER="0" ALT="Help"></A>
</TD>
</TR>
</TABLE>
<!--// END OF LINK ITEMS //-->
</TD>
<TD valign=top align=right>
<IMG SRC="/printer/spacer.gif" HEIGHT=10>
<BR>
<A HREF="http://solutions.brother.com/cgi-bin/solutions.cgi?MDL=prn043&LNG=en&SRC=DEVICE"><IMG SRC="/pbio/model_s.gif" ALT="Brother" WIDTH="144" HEIGHT="45" BORDER="0"></A>
</TD>
<TD width="20"></TD>
</TR>
</TBODY>
</TABLE>
 
</DIV>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 HEIGHT=380>
<TR><TD ALIGN="LEFT" VALIGN="TOP">
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
 
<TR><TD><A HREF="/bio/main.html?interface=1" CLASS="treehead">Network Configuration</A></TD></TR>
<TR><TD HEIGHT=5></TD></TR>
<TR><TD>
<TABLE BORDER=0>
<TR>
<TD VALIGN="TOP" ALIGN="RIGHT" WIDTH="50"><IMG SRC="/pbio/pas.gif" WIDTH="15" HEIGHT="19"></TD>
<TD VALIGN="TOP" ALIGN="LEFT">
<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
 
<TR>
 
<TD BGCOLOR="#FFCC66">
 
<A HREF="/bio/tcpip2002.html?interface=1" CLASS="treeitem">TCP/IP</A></TD>
 
<TD BGCOLOR="#FFCC66">
 
<A HREF="/bio/netbeui.html?interface=1" CLASS="treeitem">NetBIOS</A></TD>
 
<TD BGCOLOR="#FFCC66">
 
<A HREF="/bio/protocol.html?interface=1" CLASS="treeitem">Protocol</A></TD>
</TR>
 
</TABLE>
</TD></TR></TABLE>
</TD></TR>
 
<TR><TD ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#99CCFF" WIDTH=550>
 
<TABLE BORDER=0 CELLPADDING=0 WIDTH=100%>
<TR><TD>
<TABLE BORDER=0 CELLPADDING=0 WIDTH=100%><TR>
<TD WIDTH=10></TD>
<TD ALIGN=LEFT VALIGN=BOTTOM NOWRAP><FONT SIZE=5 COLOR="#000099"><B>Node Name</B></FONT>
 
 
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(Wired) 
 
</TD>
</TR></TABLE>
<HR WIDTH="95%"></TD></TR>
<TR><TD ALIGN=CENTER>
<TABLE NOWRAP CELLPADDING=5 BORDER=0>
<FORM METHOD=POST ACTION="/bio/post/general.html">
<TR>
<TD NOWRAP ALIGN=LEFT VALIGN=TOP><FONT COLOR="#000099"><B>Node Name</B></FONT></TD>
<TD NOWRAP ALIGN=LEFT VALIGN=TOP>
<INPUT TYPE=TEXT SIZE=32 MAXLENGTH=32 NAME=nodename VALUE="BRN001BA9657C41" onKeyDown="checkstring()">
</TD>
</TR>
 
 
 
<INPUT TYPE=hidden NAME="interface" VALUE=1 >
 
 
<TR><TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP><HR WIDTH="100%">
<INPUT TYPE="reset" VALUE="Cancel">&nbsp;&nbsp;<INPUT TYPE="Submit" VALUE="Submit">
</TD></TR>
 
 
</FORM>
</TABLE>
</TD></TR>
</TABLE>
</TD></TR>
<TR><TD ALIGN="RIGHT" HEIGHT="40"><A HREF="#top"><IMG SRC="/pbio/backtop.gif" BORDER=0></A></TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<BR><BR>
</CENTER>
<TABLE BORDER="0" WIDTH="100%" CELLSPACING=0 CELLPADDING=0 HEIGHT="43">
<TR BGCOLOR="#000066" ALIGN="CENTER" VALIGN="TOP"> 
<TD><FONT COLOR="#FFFFFF"><BR>Copyright(C) 2000-2007 Brother Industries, Ltd. All Rights Reserved.</FONT></TD>
</TR>
</TABLE>
 
</BODY>
</HTML>

I am trying to change the Data in the edit box called "nodename"

In my code I have tried 2 ways other than using the _IEFormGetObjByName, which only works if it returns a form name.

Help on this is much appreciated, sorry for the wall of text, Thanks in advance.

Edited by hispeed_mike

Share this post


Link to post
Share on other sites
MrMitchell

Help on this is much appreciated, sorry for the wall of text, Thanks in advance.

Hi. To make it easier to read you should wrap all your code in code tags. Highlight the code in your post and click the "<>" icon and it will insert code tags around the highlighted text. You should be able to edit your post and do this, if you like.

Share this post


Link to post
Share on other sites
PsaltyDS

First, what MrMitchell said about using code tags.

Your existing code does not look for a name or id on the form element, it loops through all forms in the collection and searches for an element called "nodename":

$colForms = _IEFormGetCollection($nav)

For $oForm In $colForms
    $oFormElements = _IEFormElementGetCollection($oForm)
    For $oFormElement In $oFormElements
        If $oFormElement.id = 'nodename' Then
            _IEFormElementSetValue($oFormElement, "Found You")
        EndIf
    Next
Next

The matching element appears to be:

<INPUT TYPE=TEXT SIZE=32 MAXLENGTH=32 NAME=nodename VALUE="BRN001BA9657C41" onKeyDown="checkstring()">

Put _IEErrorHandlerRegister() near the top of your script and run it in SciTE to see the error output in the console. See if that gives you some clues.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
hispeed_mike

First, what MrMitchell said about using code tags.

Your existing code does not look for a name or id on the form element, it loops through all forms in the collection and searches for an element called "nodename":

$colForms = _IEFormGetCollection($nav)

For $oForm In $colForms
    $oFormElements = _IEFormElementGetCollection($oForm)
    For $oFormElement In $oFormElements
        If $oFormElement.id = 'nodename' Then
            _IEFormElementSetValue($oFormElement, "Found You")
        EndIf
    Next
Next

The matching element appears to be:

<INPUT TYPE=TEXT SIZE=32 MAXLENGTH=32 NAME=nodename VALUE="BRN001BA9657C41" onKeyDown="checkstring()">

Put _IEErrorHandlerRegister() near the top of your script and run it in SciTE to see the error output in the console. See if that gives you some clues.

:mellow:

--> COM Error Encountered in HS_NETPRINT_SETUP.au3
----> $IEComErrorScriptline = 2547
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = Unspecified error
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in HS_NETPRINT_SETUP.au3
----> $IEComErrorScriptline = 1201
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable must be of type 'Object'.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in HS_NETPRINT_SETUP.au3
----> $IEComErrorScriptline = 1201
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable must be of type 'Object'.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in HS_NETPRINT_SETUP.au3
----> $IEComErrorScriptline = 1202
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable must be of type 'Object'.
----> $IEComErrorDescription = 

----> $IECom----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in HS_NETPRINT_SETUP.au3
----> $IEComErrorScriptline = 49
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable is not of type 'Object'.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0ErrorLastDllError = 0

There is the output, Variable is not of type 'Object' ??????

Any ideas?, thanks for the heads up on the <> code option when posting.

Share this post


Link to post
Share on other sites
PsaltyDS

What do lines 2547 and 1201 of your HS_NETPRINT_SETUP.au3 script look like? Since you don't do any error checking in your script, probably when line 2547 failed the IE objects used from that point on were invalid.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
hispeed_mike

What do lines 2547 and 1201 of your HS_NETPRINT_SETUP.au3 script look like? Since you don't do any error checking in your script, probably when line 2547 failed the IE objects used from that point on were invalid.

:mellow:

Line 2547 is Return $o_object.document of the Function below from IE.au3

Func _IEDocGetObj(ByRef $o_object)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEDocGetObj", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    Switch __IEIsObjType($o_object, "document")
        Case True
            SetError($_IEStatus_Success)
            Return $o_object
        Case False
            SetError($_IEStatus_Success)
            Return $o_object.document
    EndSwitch
EndFunc   ;==>_IEDocGetObj

Line 1201 is SetExtended($oTemp.forms.length) of the following Function from IE.au3

Func _IEFormGetCollection(ByRef $o_object, $i_index = -1)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEFormGetCollection", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    Local $oTemp = _IEDocGetObj($o_object)
    $i_index = Number($i_index)
    Select
        Case $i_index = -1
            SetError($_IEStatus_Success)
            SetExtended($oTemp.forms.length)
            Return $oTemp.forms
        Case $i_index > -1 And $i_index < $oTemp.forms.length
            SetError($_IEStatus_Success)
            SetExtended($oTemp.forms.length)
            Return $oTemp.forms.item($i_index)
        Case $i_index < -1
            __IEErrorNotify("Error", "_IEFormGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1")
            SetError($_IEStatus_InvalidValue, 2)
            Return 0
        Case Else
            __IEErrorNotify("Warning", "_IEFormGetCollection", "$_IEStatus_NoMatch")
            SetError($_IEStatus_NoMatch, 1)
            Return 0
    EndSelect
EndFunc   ;==>_IEFormGetCollection

My script is not that long... And you are right, I am still learning alot of this, error reporting is not included, I don't have a great understanding of wrapping code and returning errors as alot of my coding is just throwing commands to windows etc. Your help is really appreciated. Thanks

Edited by hispeed_mike

Share this post


Link to post
Share on other sites
hispeed_mike

Line 2547 is Return $o_object.document of the Function below from IE.au3

Func _IEDocGetObj(ByRef $o_object)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEDocGetObj", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    Switch __IEIsObjType($o_object, "document")
        Case True
            SetError($_IEStatus_Success)
            Return $o_object
        Case False
            SetError($_IEStatus_Success)
            Return $o_object.document
    EndSwitch
EndFunc   ;==>_IEDocGetObj

Line 1201 is SetExtended($oTemp.forms.length) of the following Function from IE.au3

Func _IEFormGetCollection(ByRef $o_object, $i_index = -1)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEFormGetCollection", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    Local $oTemp = _IEDocGetObj($o_object)
    $i_index = Number($i_index)
    Select
        Case $i_index = -1
            SetError($_IEStatus_Success)
            SetExtended($oTemp.forms.length)
            Return $oTemp.forms
        Case $i_index > -1 And $i_index < $oTemp.forms.length
            SetError($_IEStatus_Success)
            SetExtended($oTemp.forms.length)
            Return $oTemp.forms.item($i_index)
        Case $i_index < -1
            __IEErrorNotify("Error", "_IEFormGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1")
            SetError($_IEStatus_InvalidValue, 2)
            Return 0
        Case Else
            __IEErrorNotify("Warning", "_IEFormGetCollection", "$_IEStatus_NoMatch")
            SetError($_IEStatus_NoMatch, 1)
            Return 0
    EndSelect
EndFunc   ;==>_IEFormGetCollection

My script is not that long... And you are right, I am still learning alot of this, error reporting is not included, I don't have a great understanding of wrapping code and returning errors as alot of my coding is just throwing commands to windows etc. Your help is really appreciated. Thanks

OK!, So just to update, after many hours and now baldness I worked out why the error...

Seems that the navigating the following way and making the page complete then started returning the $nav value correctly:

$url = "http://" & $currentip;/bio/general.html?interface=1

        
        $nav = _IECreate ($url, 0, 1, 1, 1)
        _IEnavigate ($nav, "http://" & $currentip & "/bio/general.html?interface=1", 0)

        Sleep (5000)
        $exists = WinExists ("Connect to", "")
        WinWait ("Connect to", "")
        ControlSend ("Connect to", "", "Edit2", "admin")
        ControlSend ("Connect to", "", "Edit3", "access")
        ControlClick ("Connect to", "", "Button2")

                $colForms = _IEFormGetCollection ($nav)
        
        For $oForm In $colForms
            $oFormElements = _IEFormElementGetCollection ( $oForm )
            For $oFormElement In $oFormElements
                If $oFormElement.name = 'nodename' Then 
                    ;_IEFormElementSetValue ( $oFormElement, "Found You", 0)
                    _IEAction($oFormElement, "focus")
                    _IEAction($oFormElement, "selectall")
                    Send ($printname)
                    _IEAction($oFormElement, "unselect")
                    _IEFormSubmit ($oForm, 1)
                EndIf
            Next
        Next

So I navigate to a page that does not rely on and wait for it to complete and the $nav value returns correctly, then navigate to the page that requires login and then I get the collection and all is good in the kingdom again.

Thanks all for your help, I hope this explaination could help others...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.