Select a dropdown in IE

Get help with using AutoHotkey and its commands and hotkeys
MN_AHK
Posts: 3
Joined: 15 Dec 2017, 17:32

Select a dropdown in IE

15 Dec 2017, 17:51

Hi everyone. I posted in the IRC channel earlier today and @tidbit was helpful but we couldn't figure this problem out.

I'm trying to select a value in this HMTL drop down code, either by the text itself, the number value, or it's position on the list. I've tried various forms of getElementByID, getElementByClassName, Control/Choose, and querySelector/selectedIndex. I'd post a specific sample but nothing I try seems to interact with the drop down. I attempted to just bypass a COM solution by using send {TAB} to navigate down the page and typing in a value (which is possible) but it's not a very elegant solution and creates a whole host of other issues.

Here's my current code, everything else is working fine because every other field isn't a stupid drop down:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Here's the snippet of code I'm attempting to interact with. The dropdown value options is actually much longer but I cut out of a chunk of it to make the formatting a little less obnoxious.

Code: [Select all] [Download] GeSHi © Codebox Plus

<div class="form-field-box odd" id="order_instructions_id_field_box">
<div class="form-display-as-box" id="order_instructions_id_display_as_box">
Order Instructions :
</div>
<div class="form-input-box" id="order_instructions_id_input_box">
<select name="order_instructions_id" class="chosen-select" id="field-order_instructions_id" style="width: 300px; display: none;" data-placeholder="Select Order Instructions"><option value=""></option><option value="251.0">XPO LOGISTICS HYDRANTS INSPECTION SISTER COMPANY</option><option value="252.0">XPO LOGISTICS HYDRANTS INSPECTION VENDOR</option><option value="249.0">XPO LOGISTICS HYDRANTS SERVICE SISTER COMPANY</option><option value="250.0">XPO LOGISTICS HYDRANTS SERVICE VENDOR</option><option value="265.0">XPO LOGISTICS KITCHEN SYSTEM INSPECTION SISTER COMPANY</option><option value="266.0">XPO LOGISTICS KITCHEN SYSTEM INSPECTION VENDOR</option><option value="267.0">XPO LOGISTICS KITCHEN SYSTEM SERVICE SISTER COMPANY</option><option value="268.0">XPO LOGISTICS KITCHEN SYSTEM SERVICE VENDOR</option><option value="255.0">XPO LOGISTICS PRE-ACTION INSPECTION SISTER COMPANY</option><option value="256.0">XPO LOGISTICS PRE-ACTION INSPECTION VENDOR</option><option value="253.0">XPO LOGISTICS PRE-ACTION SERVICE SISTER COMPANY</option><option value="254.0">XPO LOGISTICS PRE-ACTION SERVICE VENDOR</option><option value="259.0">XPO LOGISTICS SPECIAL HAZARD INSPECTION SISTER COMPANY</option><option value="260.0">XPO LOGISTICS SPECIAL HAZARD INSPECTION VENDOR</option><option value="257.0">XPO LOGISTICS SPECIAL HAZARD SERVICE SISTER COMPANY</option><option value="258.0">XPO LOGISTICS SPECIAL HAZARD SERVICE VENDOR</option><option value="263.0">XPO LOGISTICS SPRINKLER INSPECTION SISTER COMPANY</option><option value="264.0">XPO LOGISTICS SPRINKLER INSPECTION VENDOR</option><option value="261.0">XPO LOGISTICS SPRINKLER SERVICE SISTER COMPANY</option><option value="262.0">XPO LOGISTICS SPRINKLER SERVICE VENDOR</option></select><div title="" class="chosen-container chosen-container-single" id="field_order_instructions_id_chosen" style="width: 300px;"><a tabindex="-1" class="chosen-single chosen-default"><span>Select Order Instructions</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off"></div><ul class="chosen-results"></ul></div></div> </div>
<div class="clear"></div>
</div>


I just want to select an option from the drop down list. Any help would be greatly appreciated.
User avatar
Gio
Posts: 401
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: Select a dropdown in IE

15 Dec 2017, 19:25

Hello MN_AHK.

Welcome to the AutoHotkey community forums.

Try either

1 - Select entry by value:
wb.document.getElementById("field-order_instructions_id").value := "252.0"

or

2 - Select entry by position:
wb.document.all.order_instructions_id[2].setAttribute("selected", "selected")

Best wishes.
"What is suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!
MN_AHK
Posts: 3
Joined: 15 Dec 2017, 17:32

Re: Select a dropdown in IE

15 Dec 2017, 20:40

Thanks for the response Gio. I’ll be trying it first thing Monday morning
MN_AHK
Posts: 3
Joined: 15 Dec 2017, 17:32

Re: Select a dropdown in IE

18 Dec 2017, 09:09

Gio wrote:Hello MN_AHK.

Welcome to the AutoHotkey community forums.

Try either

1 - Select entry by value:
wb.document.getElementById("field-order_instructions_id").value := "252.0"

or

2 - Select entry by position:
wb.document.all.order_instructions_id[2].setAttribute("selected", "selected")

Best wishes.


The first option worked like a charm. Thank you very much Gio!

Return to “Ask For Help”

Who is online

Users browsing this forum: Flipeador, jamesrize, victorzale and 54 guests