Solved

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

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

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

Suggested Solutions

Title # Comments Views Activity
Web Form VB.Net  import CSV 4 43
Regex validation 2 28
ASP.NET (VB) return a record 2 35
VB.net -  GroupBox / Panel DataBinding and behavior 3 12
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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