IE COM Dropdown- Find the Index Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aromero
Posts: 51
Joined: 01 Aug 2016, 11:53

IE COM Dropdown- Find the Index

19 Sep 2018, 13:40

There is a web page with a drop down list with code such as:
<select name="StrengthUnitOfMeasure" id="StrengthUnitOfMeasure"><option title="" value=""></option>
<option title="mg" value="adf1389d-7aa1-df11-ba1c-0024818f4b0a">%</option>
<option title="ml" value="7b254ea1-6490-e411-9816-0050568d6f80">500</option>
<option title="mcg" value="8f254ea1-6490-e411-9816-0050568d6f80">6000</option>
<option title="liters" value="5de449f0-a0bb-e411-b554-0050568d6f80">Actuation</option>
<option title="gallons" value="57424f26-a2c5-e311-9216-005056042544">APP(S)</option>
<option title="lbs" value="b1fbdd1c-72a6-e411-b4c9-0050568d6f80">BG</option>
</select>

I have a spreadsheet that has values like mcg, lbs that I am using to populate the web page drop down list. I can use the selected index command to change this drop down box but I'm not sure how to relate the values like mcg to the correct index value.

Code: Select all

wb.document.getElementById("StrengthUnitOfMeasure").selectedIndex := 2
I also need a check to ensure that the value in the spreadsheet is actually a value in the drop down list, for example if the spreadsheet value is tons and that isn't in the drop down box, I need to display a msgbox. I'm looking for ideas on how to do this. Is there a way to populate an array with all the drop down values then screen those values against my spreadsheet value? Any easier way to do this?
aromero
Posts: 51
Joined: 01 Aug 2016, 11:53

Re: IE COM Dropdown- Find the Index  Topic is solved

20 Sep 2018, 09:50

I was researching this more and found that the StrengthUnitOfMeasure drop down box contains an array of the values in the drop down box so you are able to use the following code to find and select values in the drop down boxx:

Code: Select all

test := wb.document.getElementById("StrengthUnitOfMeasure")

loop, % test.length
{
	i := A_index - 1
	if (test[i].text = "mg")
	{
		msgbox mg found at position %i%
		test.selectedIndex := i
	}
}

I made a function so I can more easily use the code . If you have any suggestions on the code, please let me know.

Code: Select all

wb := WBGet()
SelectInDropDown(wb.document.getElementById("StrengthUnitOfMeasure"), sUnit)


SelectInDropDown(element, find)
{		
	Found = "FALSE"
	loop, % element.length
	{
		i := A_index - 1		
		if (element[i].text = find)
		{
			element.selectedIndex := i
			Found := "TRUE"
		}
	}
	if (Found != "TRUE")
	{
		SoundBeep 523, 1500
		MsgBox % "Item Not Found `nSearched: " . element.name . " for " . find . "`nExiting....."
	}
	IfMsgBox, OK
		Exit
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Insanibaccha and 226 guests