Sign in to follow this  
Followers 0
Manic

AutoIt - picking wrong form

5 posts in this topic

Hey all,

I couldn't find any solutions on this problem so I thought that somebody could lend me a hand.

Problem: The website I am dealing with has TWO forms. Neither of these forms has a name or id, therefore, I am using the _IEFormGetCollection and the _IEFormElementGetCollection to enter text into the SECOND form on the website. However, my code will only pick up the first form, and enter the "hello world" into that form. Any help would be greatly appreciated!

My code (exact same except for the website)

$oIE = _IECreate("http://www.RANDOMWEBSITE.com")
$oForm = _IEFormGetCollection ($oIE, 1)
$oQuery = _IEFormElementGetCollection ($oForm, 0)
_IEFormElementSetValue ($oQuery, "hello world")
_IEFormSubmit ($oForm)

The website's code:

<form method="GET" action="blah">

<input type="text" name="hello" size="20">

<input type="submit" value="Submit">

</form>

<form method="POST" action="kittens">

<input type="text" name="animals" size="20">

<input type="submit" value="A button">

</form>

Share this post


Link to post
Share on other sites



Without an url, or full source it won't be easy to help. There ar no obvious flaws in your code at least.

It sounds like you might just have the index wrong, but I assume you checked that.

What you could do is get the form collection and loop through it with a For...In loop, to see if that manages to get the right form. (along with all others, just to test) If that doesn't get the right form I don't think you'll get it using _IEFormGetCollection()

In your example the element you are trying to use has name="animals" couldn't you use that to identify the element directly after _IECreate?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hey Tvern, thanks for the quick reply!

Unfortunately, the website is not available publicly.

I'm not 100% certain whether my index is wrong or not. How would I check this?

Next, is there an example of this For... In loop that you're talking about? This might help me reduce problems like this in the future!

Also, I tried identify the element directly after the _IECreate. Here's what I have now:

$oIE = _IECreate ("http://www.RANDOMWEBSITE.com")
$oForm = _IEFormGetCollection ($oIE)
$oQuery = _IEFormElementGetObjByName ($oForm, "animals") 
_IEFormElementSetValue ($oQuery, "puppy") 
_IEFormSubmit ($oForm)

Thanks again for your help! :)

Edited by Manic

Share this post


Link to post
Share on other sites

I'm not 100% certain whether my index is wrong or not. How would I check this?

This script will attempt to change the value for each form element it can find to display it's form/element index, which you can then use in your script.

#include <IE.au3>
Global $iForm = 0, $iElement = 0
Global $oIE = _IECreate("http://www.cs.tut.fi/~jkorpela/forms/testing.html") ;Example that works, substitute your site.
For $oForm In _IEFormGetCollection ($oIE) ;Get all available forms and loop through them
    For $oElement In _IEFormElementGetCollection ($oForm) ;Get all available element in a form and loop through em.
        _IEFormElementSetValue ($oElement,"Form" & $iForm & " Element" & $iElement) ;change the value of the element to it's form/element index for easy recognition
        $iElement += 1
    Next
    $iElement = 0
    $iForm += 1
Next

If this doesn't change the value of the element, something is blocking it. I think IFrames commonly cause this. If the form is in an Iframe, try to get the IFrame object first, or navigate directly to the page it embeds. (Just guessing wildly here)

Share this post


Link to post
Share on other sites

Hey Tvern,

sorry for the late reply! I managed to make the script work like I wanted. Essentially, it spits the text I want to enter into each input box (although I only need the second box to contain text, the first box isn't going to be submitted, therefore it is a known bug in my script), and then click the proper submit button.

Thank you so much for your assistance! :)

Manic

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