I am currently trying to manipulate a drop down box on a web site. I can change the values, however they do not seem to actually take. I am currently using this code:
The object ("ctl00_cphMain_ddlLocation") is a drop down box. Rather than iserting the value "84", I think I need to use the 'selected index'. I just do not know how. Could someone please give me an example.
All my Googling points to using FindByValue or FindByText to return the item and then setting Selected = True. Are you really really sure that ctl00_cphMain_ddlLocation is the dropdown you want?
I'm thinking I need to get a little more creative. Is it possible to select the object and use a key stroke like up arrow? If so, would you have a code example for using keystokes? When manually using the page the 'up arrow' fires the event I'm looking for.
Joseph wrote:The object ("ctl00_cphMain_ddlLocation") is a drop down box. Rather than iserting the value "84", I think I need to use the 'selected index'. I just do not know how. Could someone please give me an example.
I don't code in ASP.Net, but the general principle should be the same...
To set the <select> to a particular <option>, you can use:
Private Sub CommandButton1_Click()
Dim IE As Object
Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = True
.navigate ("http://rlgwsweb01h1.roadlink.net:90/reports/loadbylocation2rebate_DataT.aspx")
While .Busy Or .readyState <> 4: DoEvents: Wend
'set location
Set L = IE.document.all("ctl00_cphMain_ddlLocation")
'set department
Set D = IE.document.all("ctl00_cphMain_lbDepartment")
'set from date
Set F = IE.document.all("ctl00_cphMain_txbFromDate")
'set to date
Set D = IE.document.all("ctl00_cphMain_txbToDate")
'set rate group
Set R = IE.document.all("ctl00_cphMain_lbRateGroup")
'Automate Location
L.fireevent ("onchange")
L.selectedindex = 1
End With
End Sub
Does change the index to what I want without error, however it does not fire to activate the remaining objects. Is there a way to fire the event?
If the <select> has an onchange event handler, it should fire automatically when you change the selectedIndex.At least, it works that way in the non-automated context (e.g., in a web page containing client-side script). If you turn on display of script errors in IE, does anything pop up?
Edit: Actually, no, I seem to be wrong about that. You'll have to run the code yourself. No need to fire the event if you can just call the function directly.
Edit #2: In a favelet, SelectObject.fireEvent("onchange") does seem to work. After you change the selectedIndex, of course.