Solved

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

Posted on 2014-10-21
1
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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