Sign in to follow this  
Followers 0
blkshadow82

IE - With data-bind - _IEFormElementOptionSelect - Not selecting

2 posts in this topic

#1 ·  Posted (edited)

Website that I have about 100 programs wrapped around just updated their site code.  I have the majority figured out but there is this drop down option select that has a data-bind.  I think my problem will be solved with some sort of fireevent. But I cannot figure which one. It could also be how I am selecting the options as well.  Here is the code that I have(I got desperate and just loaded up a bunch of fireevents and none of them fixed my issue. I left them in just to show which ones I tried so far)

HTML

<select style="height: 31px;" id="QuickSearch_CountyId" class="text-box single-line county-selector" name="QuickSearch.CountyId" data-bind="options: shell.lookups().counties, optionsText: 'description', optionsValue: 'id', value: searchVm.crits.co3"><option value="XCA">California</option><option value="ALA">Alameda, CA</option><option value="ALP">Alpine, CA</option><option value="AMA">Amador, CA</option><option value="BUT">Butte, CA</option><option value="CAL">Calaveras, CA</option><option value="COL">Colusa, CA</option><option value="CCX">Contra Costa, CA</option><option value="DNX">Del Norte, CA</option><option value="EDX">El Dorado, CA</option><option value="FRE">Fresno, CA</option><option value="GLE">Glenn, CA</option><option value="HUM">Humboldt, CA</option><option value="IMP">Imperial, CA</option><option value="INY">Inyo, CA</option><option value="KER">Kern, CA</option><option value="KIN">Kings, CA</option><option value="LAK">Lake, CA</option><option value="LAS">Lassen, CA</option><option value="LAX">Los Angeles, CA</option><option value="MAD">Madera, CA</option><option value="MRN">Marin, CA</option><option value="MPA">Mariposa, CA</option><option value="MEN">Mendocino, CA</option><option value="MER">Merced, CA</option><option value="MOD">Modoc, CA</option><option value="MNO">Mono, CA</option><option value="MON">Monterey, CA</option><option value="NAP">Napa, CA</option><option value="NEV">Nevada, CA</option><option value="ORG">Orange, CA</option><option value="PLA">Placer, CA</option><option value="PLU">Plumas, CA</option><option value="RIV">Riverside, CA</option><option value="SAC">Sacramento, CA</option><option value="SBT">San Benito, CA</option><option value="SBD">San Bernardino, CA</option><option value="SDX">San Diego, CA</option><option value="SFX">San Francisco, CA</option><option value="SJX">San Joaquin, CA</option><option value="SLO">San Luis Obispo, CA</option><option value="SMX">San Mateo, CA</option><option value="SBX">Santa Barbara, CA</option><option value="SCL">Santa Clara, CA</option><option value="SCR">Santa Cruz, CA</option><option value="SHA">Shasta, CA</option><option value="SIE">Sierra, CA</option><option value="SIS">Siskiyou, CA</option><option value="SOL">Solano, CA</option><option value="SON">Sonoma, CA</option><option value="STA">Stanislaus, CA</option><option value="SUT">Sutter, CA</option><option value="TEH">Tehama, CA</option><option value="TRI">Trinity, CA</option><option value="TUL">Tulare, CA</option><option value="TUO">Tuolumne, CA</option><option value="VEN">Ventura, CA</option><option value="YOL">Yolo, CA</option><option value="YUB">Yuba, CA</option></select

SECTION OF MY CODE

Do


$oSelect = _IEGetObjById($oIE,"QuickSearch_CountyId")
until isobj($oSelect)
_IEAction ($oSelect, "focus")
_IEAction ($oSelect, "click")
_IEAction ($oSelect, "enable")
_IEAction ($oSelect, "click")
_IEAction ($oSelect, "enable")
$oSelect.fireevent("onkeypress")
$oSelect.fireevent("onkeydown")
$oSelect.fireevent("onkeyup")
$oSelect.fireevent("onchange")
$oSelect.fireevent("oninput")
$oSelect.fireevent("onclick")
$oSelect.fireevent("onmousedown")
$oSelect.fireevent("onmouseup")
$oSelect.fireevent("ondblclick")
$oSelect.fireevent("onblur")
$oSelect.fireevent("onsubmit")
$oSelect.fireevent("onpropertychange")
$oSelect.fireevent("onselect")
$oSelect.fireevent("onfocusin")
$oSelect.fireevent("onfocusout")
_IEAction ($oSelect, "blur")

_IEAction ($oSelect, "focus")


#Region ### Select County on PQ
if $sCountyValue = 'California' then
_IEFormElementOptionSelect ($oSelect, 'XCA', 1, 'byValue',0)
elseif $sCountyValue = 'Alameda' then
_IEFormElementOptionSelect ($oSelect, 'ALA', 1, 'byValue')
elseif $sCountyValue = 'Alpine' then
_IEFormElementOptionSelect ($oSelect, 'ALP', 1, 'byValue')
elseif $sCountyValue = 'Amador' then
_IEFormElementOptionSelect ($oSelect, 'AMA', 1, 'byValue')
elseif $sCountyValue = 'Butte' then
_IEFormElementOptionSelect ($oSelect, 'BUT', 1, 'byValue')
elseif $sCountyValue = 'Calaveras' then
_IEFormElementOptionSelect ($oSelect, 'CAL', 1, 'byValue')
elseif $sCountyValue = 'Colusa' then
_IEFormElementOptionSelect ($oSelect, 'COL', 1, 'byValue')
elseif $sCountyValue = 'Contra Costa' then
_IEFormElementOptionSelect ($oSelect, 'CCX', 1, 'byValue')
elseif $sCountyValue = 'Del Norte' then
_IEFormElementOptionSelect ($oSelect, 'DNX', 1, 'byValue')
Endif

Do
$oSelect = _IEGetObjById($oIE,"QuickSearch_CountyId")
until isobj($oSelect)
_IEAction ($oSelect, "focus")
_IEAction ($oSelect, "click")
_IEAction ($oSelect, "enable")
$oSelect.fireevent("onkeypress")
$oSelect.fireevent("onkeydown")
$oSelect.fireevent("onkeyup")
$oSelect.fireevent("onchange")
$oSelect.fireevent("oninput")
$oSelect.fireevent("onclick")
$oSelect.fireevent("onmousedown")
$oSelect.fireevent("onmouseup")
$oSelect.fireevent("ondblclick")
$oSelect.fireevent("onblur")
$oSelect.fireevent("onsubmit")
$oSelect.fireevent("onpropertychange")
$oSelect.fireevent("onselect")
$oSelect.fireevent("onfocusin")
$oSelect.fireevent("onfocusout")
_IEAction ($oSelect, "blur")
_IEAction ($oSelect, "focus")

I found this from another post and think it might help me but I am not sure what it means in terms of actual application. .:

Just a warning. A SELECT element has one or more OPTION children. It is the Option.Selected property that actually holds the value for the SELECT (think about Multiple Select). The SELECT.VALUE property may or may not work - it is in IE, but is not part of the standard and falls apart when multiple select is used.



Since jQuery is apparently in use here, I'd suggest that there may be other events expected in addition to what is called by _IEFormElementOptionSelect (take a look at the source in IE.au3).

Dale

 

I did try $oSelect.value = "CCX" in place of _IEFormElementOptionSelect ($oSelect, 'CCX', 1, 'byValue') but that did not work either. 

The way I have it written shows the value appearing in the box itself but when I try to run the search on their site it returns with no records.  If I select a different option with my mouse and change it back to the actual option I want to select, it then returns the value I am seeking.  So I know I am connected to the object, just not selecting the value correctly.

Any insight would be much appreciated.

Edited by blkshadow82

Share this post


Link to post
Share on other sites



after more extensive searching on the forum, these scripts fixed my issue:

$oEvt = $oIE.document.createEvent("HTMLEvents")
$oEvt.initEvent("keydown", True, False)
$oQuery4.dispatchEvent($oEvt)

 

AND THIS ONE:

Func _SilentEvent($o_Object, $o__IE, $__the_event = "click")     
   If NOT IsObj($o__IE) then Return SetError(1)     ;disable "IE click" sound     
   Local $sDefault = RegRead("HKEY_CURRENT_USERAppEventsSchemesAppsExplorerNavigating.Current", "")     
   RegWrite("HKEY_CURRENT_USERAppEventsSchemesAppsExplorerNavigating.Current", "", "REG_EXPAND_SZ", "")     
   Local $o_Evt = $o__IE.document.createEvent("HTMLEvents")     
   $o_Evt.initEvent($__the_event, True, False)     
   $o_Object.dispatchEvent($o_Evt)     ;re-enable "IE click" sound     
   RegWrite("HKEY_CURRENT_USERAppEventsSchemesAppsExplorerNavigating.Current", "", "REG_EXPAND_SZ", $sDefault)     
   Return 1
EndFunc   ;==>_SilentClick

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

  • Similar Content

    • taylansan
      By taylansan
      Hi All, 
      I have a question related to _IEFormElementOptionSelect in the reference file. This drop down contains three items; Homepage, Midipage, Freepage. 
      How can I get the name of these items? If I use .innertext, in another drop down list contains spaces, so I cannot split them. 
      ; Open a browser with the form example, get reference to form, get reference ; to select element, cycle 10 times selecting options byValue, byText and byIndex #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample") _IEAction($oSelect, "focus") For $i = 1 To 10 _IEFormElementOptionSelect($oSelect, "Freepage", 1, "byText") Sleep(10) _IEFormElementOptionSelect($oSelect, "midipage.html", 1, "byValue") Sleep(10) _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex") Sleep(10) Next _IEQuit($oIE) ;== Question == $aItems = StringSplit($oSelect.innerText, " ") For $i = 1 To $aItems[0] - 1 ConsoleWrite("Item-" & $i & ": " & $aItems[$i] & @CRLF) Next  
    • icu
      By 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:



      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