Sign in to follow this  
Followers 0
Iceburg

Web Form / Changing Index

8 posts in this topic

I have an issue with a web form, and I don't think I understand the logic that I should be using.

What I have is this:

A webpage loads, and I need to submit a form, sometimes the form is index 3, sometimes the form is index 2 depending on the schedule of flights that I am working with. I need to automate the testing of this website, and this is the only part I am having issues with.

The issue that I am getting to is when I call the line:

$oForm = _IEFormGetCollection ($oIE, $accept_form_accept)

MyErrFunc is called, and IE is reloaded (per my IE function) and the form is never sent.

My goal of the code was the following:

1.) Get number of forms

2.) Start with the highest form number, test and see if one of the element's has the name "flight_number" in it, and if it does

then submit that form.

3.) If that form doesn't contain the element name, reduce the form number by 1, and try that form

$oDoc = _IEDocGetObj($oIE) 
    $oArray = $oDoc.getElementsByTagName("input")
    for $element in $oArray
        if StringInStr($element.name, 'flight_number') > 0 Then 
            _IEAction($element, "click")
            sleep(6000)
            
            
            local $accept_form_accept = 4
            local $error_form_accept = 7
            local $error_element_accept = 7

            while $error_form_accept <> 0 
                ConsoleWrite("Accept form Index = " & $accept_form_accept & " Should be 4 to start and decrease by 1 until form is submitted." & @CRLF)
                ConsoleWrite("Accept $error_form_accept value set from @error is: " & $error_form_accept & " should start at 7, and when it becomes 0, will submit the form" & @CRLF)
                $oForm = _IEFormGetCollection ($oIE, $accept_form_accept)
                $error_form_accept = @error
                ConsoleWrite("Accept $error_form_accept value set from @error is: " & $error_form_accept & " should start at 7, and when it becomes 0, will submit the form" & @CRLF)
                if $error_form_accept = 0 then
                    $oQuery = _IEFormElementGetObjByName ($oForm, "send")
                    $error_element_accept = @error
                    if $error_element_accept = 0 then 
                        _IEFormSubmit ($oForm)
                        sleep(6000)
                        ExitLoop(2)
                    EndIf
                elseif $error_form_accept = 7 then
                    ExitLoop
                EndIf
                $accept_form_accept = $accept_form_accept - 1
                ConsoleWrite("Accept form Index = " & $accept_form_accept & " Should be 4 to start and decrease by 1 until form is submitted." & @CRLF)
                if $accept_form_accept = -1 then 
                    ExitLoop(2)
                    sleep(6000)
                EndIf
            WEnd
        EndIf
    Next

Share this post


Link to post
Share on other sites



So I presume that MyErrFunc is set up as a COM error handler with _IEErrorHandlerRegister? If so, what errors are being trapped? Are you saying you don't understand why the error handler is being called or something else?

As a note, you can replace these two lines:

$oDoc = _IEDocGetObj($oIE)

$oArray = $oDoc.getElementsByTagName("input")

With:

_IETagnameGetCollection($oIE)

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hi Dale,

Thanks for the reply, you are correct about MyErrFunc it is set up as a COM error handler with _IEErrorHandlerRegister.

Console Output:

Accept form Index = 4 Should be 4 to start and decrease by 1 until form is submitted.

Accept $error_form_accept value set from @error is: 7 should start at 7, and when it becomes 0, will submit the form

--> IE.au3 V2.4-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

Accept $error_form_accept value set from @error is: 7 should start at 7, and when it becomes 0, will submit the form

S:\flight_number.au3 (45) : ==> The requested action with this object has failed.:

if StringInStr($element.name, 'flight_number') > 0 Then

if StringInStr($element.name^ ERROR

>Exit code: 1 Time: 27.576

This same section of code works to count the number of flights, and start the loop, I don't understand why I get an error there.

Basically the problem is multiple forms, one of the forms has an element named flight_number, I need to find which form that is, and then submit the form. This code seems long to do all that, so I don't know if there is someway better to accomplish what I am doing.

Share this post


Link to post
Share on other sites

To troubleshoot, add these two lines before $oForm = _IEFormGetCollection ($oIE, $accept_form_accept)

_IEFormGetCollection($oIE)

ConsoleWrite("Number of Forms: " & @extended & "$accept_form_accept: " & $accept_form_accept & @CRLF)

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Debug:

Number of Forms: 3$accept_form_accept: 3

--> IE.au3 V2.4-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

Accept $error_form_accept value set from @error is: 7 should start at 7, and when it becomes 0, will submit the form

S:\flight_number.au3 (50) : ==> The requested action with this object has failed.:

if StringInStr($element.name, 'flight_number') > 0 Then

if StringInStr($element.name^ ERROR

>Exit code: 1 Time: 25.753

Share this post


Link to post
Share on other sites

If there are 3 forms, the index of the last one is 2, not 3 (the index is zero-based).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thanks again Dale,

I understand what your saying, but... sometimes the page has 5 forms, sometimes 4, and sometimes 3, which is why I started with the highest possible index (+1) just in case they code more in. I have changed the code so that the index starts at 2 (0, 1, 2 numbered forms) and it works for one flight, at the second one the form doesn't exist (0, 1 index) so it doesn't work and we get that same error since its can't find $accept_form_accept = 2 when there is only 0,1 for forms.

The logic should work like the following, and it does for the most part except calls MyErrFunc in the middle of the loops, and exits when the there aren't enough expected forms. I guess I could put some logic in that says if there are only 2 forms (0,1 - logout, and search) to just continue, and if there are (0,1,2 +) forms to continue and that would get rid of some of the problem.

1.) See how many forms there are

2.) Start loop with the highest numbered index

3.) Looks at objects

4.) If there is an element named flight_status anywhere in the form then submit that form. (and its not alway there)

5.) If there is not an element named flight_status anywhere, then reduce the form index by 1, and try again.

One more caveat is that I have got it to work as just a script for this single function (difference being that there is no Error Handler, so IE doesn't restart. (I have _openIE at the end of error handler to handle some other issues, close IE, reopen, reattach)

Share this post


Link to post
Share on other sites

Why not just base your looping variable on the number of forms on the page? My example demonstrates that @extended holds this number after a call to _IEFormGetCollection.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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