Jump to content

_IEFormElementOptionSelect Help Please [solved]


icu
 Share

Recommended Posts

Dear AutoIt Community,

I'm trying to get AutoIt to loop through three drop-down selection boxes in IE. The picture below is of the boxes I want to loop through:

post-64643-0-38387400-1315071037_thumb.j

After much trial and error I've managed to get AutoIt to read all of the options of the first selection box into an array. My plan was to use a For In Next loop several times to get AutoIt to select each option from each box one-by-one and submit the form.

Below is an example of my code so far:

#include <IE.au3>
#include <Array.au3>
$s_1stCountry = ""
$s_URL = "www.autoitforumexample.com"
$o_IE = _IECreate ($s_URL)
_IELoadWait ($o_IE)
Global $o_lstCountry_Select = _IEGetObjByName ($o_IE, "lstCountry")
Global $s_lstCountry_List = _IEPropertyGet ($o_lstCountry_Select, "innerhtml")
Global $a_lstCountry_List = StringRegExp ($s_lstCountry_List, "\>([A-Z][A-Za-z\s]+)\<", 3)
For $1stCountry In $a_lstCountry_List
$s_1stCountry = $1stCountry
_IEFormElementOptionSelect($o_lstCountry_Select, $s_1stCountry, 1, "byText")
Sleep (5000)
Next

And below is a sample of the webpage code for the first selection box:

<th>Country:</th>
<td><select name="lstCountry" onchange="javascript:setTimeout('__doPostBack(\'lstCountry\',\'\')', 0)" language="javascript" id="lstCountry" style="width:250px;">
    <option value="0"></option>
    <option selected="selected" value="10659">Albania</option>
    <option value="3506">Andorra</option>
    <option value="3687">Antigua and Barbuda</option>
    <option value="5647">Argentina</option>
    <option value="10686">Aruba</option>
    <option value="3623">Australia</option>
    <option value="3508">Austria</option>
    <option value="5657">Bahamas</option>
    <option value="9849">Bahrain</option>
...code keeps going and going

When running my code I can get AutoIt to correctly select the first country "Andorra", however I get the following console error as AutoIt attempts to loop through the other countries:

--> IE.au3 V2.4-0 Error from function _IEFormElementOptionselect, $_IEStatus_InvalidObjectType

I really have no idea what I'm doing wrong here. How can the object be an invalid type if it worked first time? I've also tried using the byIndex $s_mode and not had any luck.

Any and all help is much appreciated.

Kind regards,

icu

Edited by icu
Link to comment
Share on other sites

If the page refreshes after you select an option, the original document is destroyed (along with your object reference), a new one is created and you need to get a new object reference.

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

Link to comment
Share on other sites

Thank you Dale for your insight. I've modified my code accordingly and it works perfectly now.

#include <IE.au3>
#include <Array.au3>
$s_1stCountry = ""
$s_URL = "www.autoitforumexample.com"
$o_IE = _IECreate ($s_URL)
_IELoadWait ($o_IE)
Global $o_lstCountry_Select = _IEGetObjByName ($o_IE, "lstCountry")
Global $s_lstCountry_List = _IEPropertyGet ($o_lstCountry_Select, "innerhtml")
Global $a_lstCountry_List = StringRegExp ($s_lstCountry_List, "\>([A-Z][A-Za-z\s]+)\<", 3)
For $1stCountry In $a_lstCountry_List
$s_1stCountry = $1stCountry
_IEFormElementOptionSelect ($o_lstCountry_Select, $s_1stCountry, 1, "byText")
_IELoadWait ($o_IE)
$o_lstCountry_Select = _IEGetObjByName ($o_IE, "lstCountry")
Next
Edited by icu
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

×
×
  • Create New...