Solved

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

Posted on 2014-10-21
1
226 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

18 Experts available now in Live!

Get 1:1 Help Now