Sign in to follow this  
Followers 0
FrozenTeeth

IE Form Element to value not working

9 posts in this topic

Not sure why I can't get this value into a variable. The message box returns the correct date but the $FoundDate returns a zero.

$oQuery = _IEFormElementGetObjByName ($oForm, "ddlHostBusDate")
MsgBox(0, "Form Element Value", _IEFormElementGetValue ($oQuery))
Global $foundDate = _IEFormElementGetValue ($oQuery)
MsgBox(0, "$foundDate", $foundDate)

Any help is appreciated.

Share this post


Link to post
Share on other sites



You'll have to post a short but complete demo script that actually shows your symptom. Can't reproduce it with just that, and this works fine:

#include <IE.au3>

$oIE = _IE_Example ("form")
$oForm = _IEFormGetObjByName ($oIE, "ExampleForm")
$oText = _IEFormElementGetObjByName ($oForm, "textExample")
$IEAu3Version = _IE_VersionInfo ()
_IEFormElementSetValue ($oText, $IEAu3Version[5])


MsgBox(0, "Form Element Value", _IEFormElementGetValue ($oText))
Global $foundDate = _IEFormElementGetValue ($oText)
MsgBox(0, "$foundDate", $foundDate)

;)


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

#3 ·  Posted (edited)

Thanks for testing that out for me. Yep I tried a test here and it works fine with the example form but when I use it on my web page (Which I have no control over) it does not work.

I think I'll have to try something else maybe read the html and check the value that way. It't the long way around but it will work ;)

This is the table I'm trying to get at:

<table class="Grid" cellspacing="0" cellpadding="0" align="Center" border="0" style="border-style:None;width:98%;border-collapse:collapse;">
    <tr>
        <td valign="Top"><table border="0" style="width:100%;">
            <tr>
                <td><span id="PageTitle" class="Head">CAT to Host Report</span></td>
            </tr>
        </table></td>
    </tr><tr>
        <td>
                &nbsp;
            </td>
    </tr><tr id="ParameterRow">
        <td valign="Top"><table border="0" style="width:100%;">
            <tr>
                <td valign="Top" style="width:40%;"><table class="NormalBold" border="0" style="width:100%;">
                    <tr id="HostBusinessDate">
                        <td valign="Top"><span id="lblHostBusDate" title="Enter a host business date or select a date from the list" style="width:130px;">Host business date</span></td><td><span id="HostBusDateFmtText" title="Enter a host business date or select a date from the list" class="NormalTextBox"><input name="HostBusDateFmtText:InnerTextBox" type="text" value="08/12/2010" maxlength="10" id="HostBusDateFmtText_InnerTextBox" style="width:200px;" /><span id="HostBusDateFmtText__ctl0" controltovalidate="HostBusDateFmtText_InnerTextBox" errormessage="Please enter the date in the format MM/DD/YYYY." display="Dynamic" evaluationfunction="RegularExpressionValidatorEvaluateIsValid" validationexpression="^((([1-9])|([0][1-9])|([1][0-2]))[/-](([1-9])|([0][1-9])|([1][0-9])|([2][0-9])|([3][0-1]))[/-](\d{4}))$" style="color:Red;display:none;">*</span></span>
                                        <br>
                                        <select name="ddlHostBusDate" onchange="__doPostBack('ddlHostBusDate','')" language="javascript" id="ddlHostBusDate" style="width:200px;">
                            <option value="10/04/2010">10/04/2010</option>
                            <option value="10/03/2010">10/03/2010</option>
                            <option value="10/02/2010">10/02/2010</option>
                            <option value="10/01/2010">10/01/2010</option>
                            <option value="09/30/2010">09/30/2010</option>
                            <option value="09/29/2010">09/29/2010</option>
                            <option value="09/28/2010">09/28/2010</option>
                            <option value="09/27/2010">09/27/2010</option>
                            <option value="09/25/2010">09/25/2010</option>
                            <option value="09/24/2010">09/24/2010</option>
                            <option value="09/23/2010">09/23/2010</option>
                            <option value="09/22/2010">09/22/2010</option>
                            <option value="09/21/2010">09/21/2010</option>
                            <option value="09/20/2010">09/20/2010</option>
                            <option value="09/18/2010">09/18/2010</option>
                            <option value="09/17/2010">09/17/2010</option>
                            <option value="09/16/2010">09/16/2010</option>
                            <option value="09/15/2010">09/15/2010</option>
                            <option value="09/14/2010">09/14/2010</option>
                            <option value="09/13/2010">09/13/2010</option>
                            <option value="09/11/2010">09/11/2010</option>
                            <option value="09/10/2010">09/10/2010</option>
                            <option value="09/09/2010">09/09/2010</option>
                            <option value="09/08/2010">09/08/2010</option>
                            <option value="09/07/2010">09/07/2010</option>
                            <option value="09/04/2010">09/04/2010</option>
                            <option value="09/03/2010">09/03/2010</option>
                            <option value="09/02/2010">09/02/2010</option>
                            <option value="09/01/2010">09/01/2010</option>
                            <option value="08/31/2010">08/31/2010</option>
                            <option value="08/30/2010">08/30/2010</option>
                            <option value="08/28/2010">08/28/2010</option>
                            <option value="08/27/2010">08/27/2010</option>
                            <option value="08/26/2010">08/26/2010</option>
                            <option value="08/25/2010">08/25/2010</option>
                            <option value="08/24/2010">08/24/2010</option>
                            <option value="08/23/2010">08/23/2010</option>
                            <option value="08/22/2010">08/22/2010</option>
                            <option value="08/21/2010">08/21/2010</option>
                            <option value="08/20/2010">08/20/2010</option>
                            <option value="08/19/2010">08/19/2010</option>
                            <option value="08/18/2010">08/18/2010</option>
                            <option value="08/17/2010">08/17/2010</option>
                            <option value="08/16/2010">08/16/2010</option>
                            <option value="08/14/2010">08/14/2010</option>
                            <option value="08/13/2010">08/13/2010</option>
                            <option selected="selected" value="08/12/2010">08/12/2010</option>
                            <option value="08/11/2010">08/11/2010</option>
                            <option value="08/10/2010">08/10/2010</option>
                            <option value="08/09/2010">08/09/2010</option>
                            <option value="08/08/2010">08/08/2010</option>
                            <option value="08/07/2010">08/07/2010</option>
                            <option value="08/06/2010">08/06/2010</option>
                            <option value="08/05/2010">08/05/2010</option>
                            <option value="08/04/2010">08/04/2010</option>
                            <option value="08/03/2010">08/03/2010</option>
                            <option value="08/02/2010">08/02/2010</option>
                            <option value="07/31/2010">07/31/2010</option>
                            <option value="07/30/2010">07/30/2010</option>
                            <option value="07/29/2010">07/29/2010</option>
                            <option value="07/28/2010">07/28/2010</option>
                            <option value="07/27/2010">07/27/2010</option>
                            <option value="07/26/2010">07/26/2010</option>
                            <option value="07/24/2010">07/24/2010</option>
                            <option value="07/23/2010">07/23/2010</option>
                            <option value="07/22/2010">07/22/2010</option>
                            <option value="07/21/2010">07/21/2010</option>
                            <option value="07/20/2010">07/20/2010</option>
                            <option value="07/19/2010">07/19/2010</option>
                            <option value="07/18/2010">07/18/2010</option>
                            <option value="07/17/2010">07/17/2010</option>
                            <option value="07/16/2010">07/16/2010</option>
                            <option value="07/15/2010">07/15/2010</option>
                            <option value="07/14/2010">07/14/2010</option>
                            <option value="07/13/2010">07/13/2010</option>
                            <option value="07/12/2010">07/12/2010</option>
                            <option value="07/10/2010">07/10/2010</option>
                            <option value="07/09/2010">07/09/2010</option>
                            <option value="07/08/2010">07/08/2010</option>
                            <option value="07/07/2010">07/07/2010</option>
                            <option value="07/06/2010">07/06/2010</option>
                            <option value="07/04/2010">07/04/2010</option>
                            <option value="07/03/2010">07/03/2010</option>
                            <option value="07/02/2010">07/02/2010</option>
                            <option value="07/01/2010">07/01/2010</option>
                            <option value="06/30/2010">06/30/2010</option>
                            <option value="06/29/2010">06/29/2010</option>
                            <option value="06/28/2010">06/28/2010</option>
                            <option value="06/27/2010">06/27/2010</option>
                            <option value="06/26/2010">06/26/2010</option>
 
                        </select></td>
                    </tr><tr id="HostID">
                        <td><span id="lblHostID" style="width:130px;">Host device Id</span></td><td><select name="ddlHostID" id="ddlHostID" style="width:200px;">
                            <option selected="selected" value="ALL">All</option>
                            <option value="1">1 - XP Host Interface</option>
                            <option value="3">3 - SB XP Acq Host Interface</option>
                            <option value="4">4 - SB Issuer Host Interface</option>
 
                        </select></td>
                    </tr><tr id="SortBy">
                        <td><span id="lblSortBy" style="width:130px;">Sort by</span></td><td><select name="ddlSortBy" id="ddlSortBy" style="width:200px;">
                            <option value="CardNbr">Card number</option>
                            <option value="MemberNbr">Member number</option>
                            <option selected="selected" value="CAT Date Time">Operation date and time</option>
 
                        </select></td>
                    </tr><tr id="ReportContent">
                        <td><span id="lblReportCont" style="width:130px;">Report content</span></td><td><select name="ddlReportCont" id="ddlReportCont" style="width:200px;">
                            <option selected="selected" value="D">Detailed report</option>
                            <option value="T">Totals only</option>
 
                        </select></td>
                    </tr><tr id="Demo">
                        <td><input id="ckTestCards" type="checkbox" name="ckTestCards" /><label for="ckTestCards">Test cards</label></td>
                    </tr><tr>
                        <td>
                                        &nbsp;
                                    </td><td><input type="image" name="SubmitImageButton" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="SubmitImageButton" title="Submit the reports" src="/CatRptCenter/images/Submit_Button.jpg" alt="" align="Middle" border="0" /></td>
                    </tr>
                </table></td><td valign="Top" style="width:60%;"><table id="SelectExportParmsCtl1_SelectExportParmsTable" class="Grid" border="0" style="width:100%;">
                    <tr>
                        <td valign="Top"><span class="NormalBold"><input id="SelectExportParmsCtl1_ExportToPdfCheckBox" type="checkbox" name="SelectExportParmsCtl1:ExportToPdfCheckBox" checked="checked" /><label for="SelectExportParmsCtl1_ExportToPdfCheckBox">Export to PDF</label></span></td>
                    </tr><tr>
                        <td><span class="NormalBold"><input id="SelectExportParmsCtl1_ExportToTextCheckBox" type="checkbox" name="SelectExportParmsCtl1:ExportToTextCheckBox" /><label for="SelectExportParmsCtl1_ExportToTextCheckBox">Export to text</label></span></td>
                    </tr><tr>
                        <td><span class="NormalBold"><input id="SelectExportParmsCtl1_ReplaceFileCheckBox" type="checkbox" name="SelectExportParmsCtl1:ReplaceFileCheckBox" checked="checked" /><label for="SelectExportParmsCtl1_ReplaceFileCheckBox">Replace file</label></span></td>
                    </tr><tr>
                        <td>
            &nbsp;
        </td>
                    </tr><tr>
                        <td valign="Top"><span title="Enter a custom file name for the exported report to use in place of the name generated by CAT" class="NormalBold">Custom export file name </span><span title="Enter a custom file name for the exported report to use in place of the name generated by CAT" class="Normal" style="color:DarkBlue;font-size:8pt;">  (Enter a name only if you do not want to accept the default name)</span></td>
                    </tr><tr>
                        <td valign="Top"><span id="SelectExportParmsCtl1_ExportFileNameFmtText" title="Enter a custom file name for the exported report to use in place of the name generated by CAT" class="NormalTextBox"><input name="SelectExportParmsCtl1:ExportFileNameFmtText:InnerTextBox" type="text" maxlength="250" id="SelectExportParmsCtl1_ExportFileNameFmtText_InnerTextBox" style="width:500px;" /></span></td>
                    </tr>
                </table>
</td>
            </tr>
        </table></td>
    </tr>
</table>
Edited by FrozenTeeth

Share this post


Link to post
Share on other sites

Did you do something between the first time _IEFormElementGetValue($oQuery) was called, and the second? For example, if you navigate the page all object references on that page become invalid and have to be retrieved again.

;)


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

Did you do something between the first time _IEFormElementGetValue($oQuery) was called, and the second? For example, if you navigate the page all object references on that page become invalid and have to be retrieved again.

;)

I open the page and set the date. Then check the date to make sure it is set correctly then submit the form. Everything is working except the checking the field for the date.

#include <IE.au3>
;
; Navigate to CAT to Host Report (Not working)
;

$oIE = _IECreate("http://ncat3420a/CatRptCenter/CatToHostReportPge.aspx", 0, 1, 1, 1)
sleep(2000)
$oForm = _IEFormGetObjByName($oIE, "XPCATMain")
$oText = _IEFormElementGetObjByName ($oForm, "ddlHostBusDate")
_IEFormElementSetValue ($oText, "08/12/2010")

MsgBox(0, "Form Element Value", _IEFormElementGetValue ($oText))
Global $foundDate = _IEFormElementGetValue ($oText)
MsgBox(0, "$foundDate", $foundDate)

Share this post


Link to post
Share on other sites

Your right! It does reset!

If I remove the line:

_IEFormElementSetValue ($oText, "08/12/2010")

The found date works fine.

How do I re-read the page?!?!?!? _IEAttach?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Normally, just setting the value doesn't invalidate the object reference to the element. But notice the HTML you posted for that element:

<select name="ddlHostBusDate" onchange="__doPostBack('ddlHostBusDate','')" language="javascript" id="ddlHostBusDate" style="width:200px;">

The interesting part is the onchange script. When you set the value and trigger the onchange event, it probably reloads the page, which means the object references have to re-acquired. The document's scripts are doing that, not the AutoIt function.

The $oIE is still valid so _IEAttach() should not be required. Just reuse $oIE, reacquire $oForm, and redo your _IEFormElementGetObjByName() to get the new objects.

;)

Edited by PsaltyDS

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

#9 ·  Posted (edited)

Thanks PsaltyDS! You have been a great help in wrapping my head around this.

This was my final code. It is not pretty but it works. I just changed the $f_fireEvent to zero then checked the text. Then I fire the event and then submit. Works!

#include <IE.au3>
$oIE = _IECreate("http://ncat3420a/CatRptCenter/CatToHostReportPge.aspx", 0, 1, 1, 1)
$oForm = _IEFormGetObjByName($oIE, "XPCATMain")
$oText = _IEFormElementGetObjByName ($oForm, "ddlHostBusDate")
_IEFormElementSetValue ($oText, "08/12/2010",0)
MsgBox(0, "Form Element Value", _IEFormElementGetValue ($oText))
Global $foundDate = _IEFormElementGetValue ($oText)
MsgBox(0, "$foundDate", $foundDate)
_IEFormElementSetValue ($oText, "08/12/2010",1)
MsgBox(0, "$foundDate", $foundDate)
if $founddate = "08/12/2010" then
    _IEFormImageClick($oIE, "SubmitImageButton", "name")
end if
_IEQuit($oIE)
exit
Edited by FrozenTeeth

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  
Followers 0