Jump to content

Automated web form Do/until loop using increasing integer?


aanons
 Share

Recommended Posts

Hello:

I am quite new to autoIT with very rusty web development skills. I was wondering if someone could just point me in the right direction. I know what I want, I just do not know the terms to search for in order to learn how to code the script that I want.

So far I have been able to use autoIT to go to successfully complete the following function:

1. Open IE and go to a specific web page.
2. Automatically type a specified number into the text field
3. And submit the form.

I want to create a do/until loop that will automate entering in a numeric variable, increasing by 1 into the text field until it finds a number that will generate a certain error message.

In case I am not explaining thoroughly enough this is what I want it to look like:

1. Open IE and go to a specific web page.
2. Automatically enter a numeric variable (ie 8675309) into the text field
3. And submit the form.
4. If the form does not generate the certain error message I am looking for, I want autoIT to move on to the next integer (ie 8675310) and so on until the message I am looking for is accomplished.

Thank you for your help!

-AA

Link to comment
Share on other sites

  • Moderators

@aanons welcome to the forum. As you mention you have the first three steps already done, you would simply need a For Loop wrapped around steps 2 and 3 to accomplish what you are after. You can look up Loops in the help file, and if you're stuck please post your code so we can see what you're doing. Also, to forestall any issues as you progress, please ensure you are familiar with the forum rules and not trying to A: bypass security measures like a CAPTCHA or B: doing something against the site's EULA or TOS.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

#include <IE.au3>

Call ("testem")

Func testem ()
   Global $oIE = _IECreate ("http://websitenamehere.com")


Local  $oForm = _IEFormGetObjByName($oIE, "cForm")
Local $cCoField = _IEGetObjByName($oIE,"cCoField")

_IEFormElementSetValue ($cCoField,"8675309")

Sleep(500)

_IEFormSubmit($oForm)

EndFunc

Spoiler

 

 

Link to comment
Share on other sites

  • Moderators

Create an array of all the numbers you want to try

Local $aNumbers[3] = [<first_number>,<second_number>,<third_number>}

Then loop through the array (again, look at the help file for For...In...Next, it has an almost perfect example for your needs). The last three lines of your function should be all you need to loop through, set the value, pause if you need, then submit the form. If, after submitting the form, the page changes, then look at _IENavigate to get you back to the right page.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

How would I insert that into my current code? I know that my input is static right now 

And do I have to insert each number and fill it into the <first_number> <second_number> sections?

And how would  I stop the script once I get to the result I want? Im trying to wrap my head around this.

 

Link to comment
Share on other sites

#include <IE.au3>
Global $oIE = _IECreate ("http://websitenamehere.com")
Global  $oForm = _IEFormGetObjByName($oIE, "cForm")
Global $cCoField = _IEGetObjByName($oIE,"cCoField")
Global $counter = 8675309

Call ("testem")

Func testem ()
    While 1
        _IEFormElementSetValue ($cCoField,"8675309")
        Sleep(500)
        _IEFormSubmit($oForm)
            ;test for whatever you're testing for here
            ;if you find it then
            ExitLoop
            ;if you don't find it
            $counter+=1
    Wend
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...