Solved

Scripting IE to use dropdown box in VB.Net using SHDocVw

Posted on 2014-10-21
1
239 Views
Last Modified: 2014-10-29
I am trying to write a little program to download some stock prices.  This is an example of the webpage I am trying to hit:

http://www.nasdaq.com/symbol/aapl/historical

In the middle of the page you can see there is a dropdown that says "Select the Timeframe: ".  I would like to change this to 2 years with the program.  This is the code I am using:

Dim wbBrowser As New SHDocVw.InternetExplorer
        wbBrowser.Visible = True
        wbBrowser.Navigate("http://www.nasdaq.com/symbol/drys/historical", Nothing, Nothing, Nothing, Nothing)
        Do
        Loop Until Not wbBrowser.Busy

 Dim HTMLDoc As mshtml.HTMLDocument

HTMLDoc = wbBrowser.Document

 Dim iHTMLCol As IHTMLElementCollection
        Dim iHTMLEle As IHTMLElement
        Dim str As String

iHTMLCol = HTMLDoc.getElementsByTagName("input")

 If Not iHTMLEle.getAttribute("name") Is Nothing Then

     iHTMLEle.click()


 End if

Open in new window


I was really just using that to try to go through the page elements and find the dropdown, but I can't even find it.  Any ideas on how to interact with the dropdown?
0
Comment
Question by:Jason_Haft
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40397262
The HTML for that element:

<select id="ddlTimeFrame" name="ddlTimeFrame" onchange="getQuotes(false)">
            <option value="5d">5 Days</option>
            <option value="1m">1 Month</option>
            <option value="3m" selected="selected">3 Months</option>
            <option value="6m">6 Months</option>
            <option value="1y">1 Year</option>
            <option value="18m">18 Months</option>
            <option value="2y">2 Years</option>
            <option value="3y">3 Years</option>
            <option value="4y">4 Years</option>
            <option value="5y">5 Years</option>
            <option value="6y">6 Years</option>
            <option value="7y">7 Years</option>
            <option value="8y">8 Years</option>
            <option value="9y">9 Years</option>
            <option value="10y">10 Years</option>
        </select>

Open in new window


You should be able to use getElementByID("ddlTimeFrame") to get the HTML element.  You can cast that element to mshtml.HTMLSelectElement.  You should be able to loop through the HTMLOptionElementCollection (options), and find the HTMLOptionElement that you would like to select.  With the correct index for the option, you should be able to set the selectedIndex property for the HTMLSelectElement.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now