Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

914 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