Jump to content
Sign in to follow this  
icu

_IEFormElementOptionSelect Help Please [solved]

Recommended Posts

icu

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

Share this post


Link to post
Share on other sites
DaleHohm

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

Share this post


Link to post
Share on other sites
icu

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

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  

  • Similar Content

    • SkysLastChance
      By SkysLastChance
      I am trying to grab the id "in2xk_26" however it the characters before the underscore always change. (in the name too)
      Is there a way I can find a id or name by the last 3 charcters?
      Using something like "stringright?"
      So I would want to search for just "_26" in this case.
      This is assuming that there are no other _26
       

      #include <Excel.au3> #include <IE.au3> #include <GUIConstantsEx.au3> Global $iMousespeed = 25,$target = "",$TagName = "",$Value = "",$Atrribute = "" $oIE = _IEAttach("MEDITECH") $TagName = "input" $Value = "in2xk_26" $Attribute = "id" $tags = $oIE.document.GetElementsByTagName($TagName) ;TagName ------ MAKE SURE TO NAME THESE For $tag in $tags $class_value = $tag.GetAttribute($Attribute) ;Attribute ------ MAKE SURE TO NAME THESE If string($class_value) = $Value Then ;Value ------ MAKE SURE TO NAME THESE $target = $tag $iScreenX = _IEPropertyGet($target, "screenx") $iScreenY = _IEPropertyGet($target, "screeny") $iWidth = _IEPropertyGet($target, "width") $iHeight = _IEPropertyGet($target, "height") $oMouseCords = MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed) MouseClick($MOUSE_CLICK_LEFT) ExitLoop EndIf Next  
       
    • SkysLastChance
      By SkysLastChance
      I was wondering how I read data inside of a iframe. I would like to be able to click something inside a iframe. However, I can't even find the tag. 
      The id and name change all the time so I can't use those. 
      The code highlighted in blue is what I am trying to click. (second picture)
      Here is what I have tried.
      $target = "" $tags = $oIE.document.GetElementsByTagName("div") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "s_92 altstyle s_93 s_94" Then $target = $tag ConsoleWrite("Tag Found " & $target.outerText&@CRLF) ExitLoop EndIf Next  

       
       

    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

    • SkysLastChance
      By SkysLastChance
      I am trying to type a name in patient summary search box. How should I go about doing this. I am clearly not doing it right. (Attached Picture of HTML code.)
      This is what I have tried. I assume this is not working because it is not a form? 
      WinActivate("MEDITECH - Internet Explorer")       Sleep (500)    $oIE = _IEAttach("MEDITECH")    $oForm = _IEFormGetObjByName($oIE, "systemMenu")    $oText = _IEFormElementGetObjByName($oForm, "sysmenu-searchbarinput") _IEFormElementSetValue($oText, "Hey! This works!")
    • aiter
      By aiter
      Just want to report a warning I get when using IE udf and running from F5 in scite

      -> IE.au3 T3.0-2 Warning from function internal function __IEIsObjType, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler)
      When I look at IE.au3 I see a comment that this function has been removed as there are no more fatal errors.
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.