Selecting an Item From a Drop Down List on a Webpage

da bobsta

New Member
Joined
Jul 12, 2019
Messages
13
[FONT=Arial, Helvetica, sans-serif]Hi,

[/FONT]I am on a webpage where there is a dropdown list to identify the applications to 'Download To'. When I manually select the 'Microsoft Excel (XLS)' option (which happens to be the first in the list), then the 'Dates From' and 'Dates To' input boxes are then displayed.

However, when I select the 'Microsoft Excel (XLS)' option using vb script "objIE.Document.getElementsByName("downloadStatementsForm.typeFile")(0).selectedIndex = 1"
, the 'Dates From' and 'Dates To' do not get displayed.


My questions:


1. Is it possible to select the text rather than the index from the Drop Down List (gets over the possibility of the order changing)?
2. What do I need to do in order for the 'Dates From' and 'Dates To' input boxes to be displayed?


Thanks, Bobby
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Here's the element details...just in case that's needed.

Code:
<select name="downloadStatementsForm.typeFile" id="sel_downloadto" class="submitonchange  correct">
	<option value="">Please choose...</option>
	<option value="1">Microsoft Excel (XLS)</option>
	<option value="2">Microsoft Money (QIF)</option>
	<option value="3">Intuit Quicken (QIF)</option>
	<option value="4">Adobe Acrobat (PDF)</option>
	<option value="5">Text file (TXT)</option>
	<option value="6">Midata (csv)</option>
</select>
 
Last edited by a moderator:
Upvote 0
Hi Bobby,

One way could be firing the "onchange" event of the select object that is most likely being listened in JavaScript code:

Code:
    With objIE.Document.getElementsByName("downloadStatementsForm.typeFile")(0)
        .selectedIndex = 1
        .FireEvent "onchange"
    End With

Could you please try and let us know? If it doesn't work, then is it possible to share the actual html page?
 
Last edited:
Upvote 0
Hi,

It doesn't work and the page is from a Bank website so not possible to share. Is there any other information I could provide you or suggestion that you might have?

Thanks, Bobby
 
Upvote 0
Can you look at the HTML source code and search for submitonchange?

You will find multiple of them, I am interested in the one located in a script section. It might not be in the HTML document directly, but also in the linked JavaScript files.

Basically, the document should be using this class selector to catch the change event of the select object (I am saying that looking at the class name, submitonchange). I am trying to see how it is implemented, so we might find other solutions.
 
Upvote 0
Is this when you right click over the object and 'Inspect'. If so, that's what I've already inlcuded. If something else, then how can I find this?
 
Upvote 0
Please try this:

Declare an object parameter in your code:

Code:
   Dim eventChange As Object

And change my previously posted 4 lines sample code with the following:

Code:
    Set eventChange = objIE.document.createEvent("HTMLEvents")
    eventChange.initEvent "change", True, False
    With objIE.document.getElementsByName("downloadStatementsForm.typeFile")(0)
        .selectedIndex = 1
        .dispatchEvent eventChange
    End With

We are creating an event object between HTML document object in VBA and Internet Explorer, and triggering it after setting the index of the Select object to trigger the actual listener. FireEvent should have actually worked but apparently it is not listened by the listener in the document you are working with.

Hope this helps.
 
Upvote 0
Hey...it works...thanks...now on to the next step...watch out for some more posts (hopefully not though!).

Thanks, Bobby
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top