Jump to content

Unknown Error/Failure with _IEFormElementOptionSelect


Recommended Posts

Dear AutoIt Community,

I'm getting random errors when looping an array that has a _IEFormElementOptionselect command in it.

My code kind of looks like the following:

#include <IE.au3>
#include <Array.au3>
; Global declares for varibles in loop
Global $i_Country_Count = 0
Global $i_Row_Count = 0
Global $i_Cell_Count = 0
$o_IE = _IECreate ("http://www.exampleurl.com")
Global $o_lstCountry_Select = _IEGetObjByName ($o_IE, "lstCountry")
Global $s_lstCountry_HTML = _IEPropertyGet ($o_lstCountry_Select, "innerhtml")
Global $ai_lstCountry_List = StringRegExp ($s_lstCountry_HTML, "=([0-9]+)\>", 3)
For $i_lstCountry In $ai_lstCountry_List
If $i_lstCountry = 0 Then
; Skip and move on to the next value, this is done because a value of '0' is the blank placeholder in the Country selection box.
$i_Country_Count += 1
_IEFormElementOptionSelect ($o_lstCountry_Select, $i_lstCountry, 1, "byValue")
_IELoadWait ($o_IE)
; Debug which Selected Country _IEFormElementOptionSelect fails on
$s_lstCountry = _ArrayToString (StringRegExp ($s_lstCountry_HTML, $i_lstCountry & "\>([A-Z][A-Za-z\s]+)\<", 3))
ConsoleWrite ("Country Number: " & $i_Country_Count & ", Selected Country: " & $s_lstCountry & @CRLF)
$o_lstCountry_Select = _IEGetObjByName ($o_IE, "lstCountry") ; This line of code is to re-establish the lstCountry object after the page is reloaded
$i_Country_Count += 1

The errors stop the program at different locations through the array loop so I'm pretty sure it's not my code. There are 143 rows in the array and my code has never done a complete pass through the array without being stopped by the error.

To give some idea of the randomness of the error, it has stopped at array row 121, 101, 81 and 114 during my testing.

I get the following console message each time:

H:\PortableApps\AutoIt\Include\IE.au3 (1341) : ==> The requested action with this object has failed.:
If $oItem.value = $s_string Then
If $oItem.value ^ ERROR

I've looked at line 1341 in IE.au3 and I can't understand what is going wrong.

This is quite worrisome for me as I was planning for two more loops using _IEFormElementOptionselect and I need a clean run as data will be inserted into a SQLite database and needs to be correct and complete.

Any and all help much appreciated.

Kind regards,


Link to comment
Share on other sites


After a night's sleep I've had another crack at it and tried using

_IEFormElementSetValue ($o_lstCountry_Select, $i_lstCountry)

...in place of

_IEFormElementOptionselect ($o_lstCountry_Select, $i_lstCountry, 1, "byValue")

...and everything worked! Tested it several times, no errors. Good for my program, bad for my learning as this baffles me.

Can any one shed any light into this? To me the lines of code are asking AutoIt to do the exact same thing.


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

  • Recently Browsing   0 members

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