• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

IE automation - Drop down box

chrisulm

New Member
I'm trying to select a year from a drop down box though Internet Explorer. I was able to login and navigate the page, but I'm absolutely stuck at this point. Any suggestions?

Code:
<tr><td valign="top">
<div class="formDiv">
<h4>Select Year</h4>
<TABLE><TR><TD><b>Please select a year:<br><br></b><SELECT name = 'Year' ID = 'Year' OnChange = 'select_year();'><OPTION>Select Year</OPTION><OPTION value = '2016'>2016</OPTION><OPTION value = '2015'>2015</OPTION><OPTION value = SELECT><br><br></TABLE></div><P></td>
</tr>
</table>
</TD></TR></TABLE></td></tr></table></BODY></HTML>
 
Here's a better looking snippet of the html from the page I'm accessing.
 

Attachments

  • Capture.PNG
    Capture.PNG
    43.9 KB · Views: 12
Hello chrisulm

Welcome to chandoo forum.

Always analyze the HTML code (Source code) of the web page and refer their "name"s or "id"s in your vba code for that matter any controls or test on the websites.

Let me know any challenges..Happy to help you.
 
Hello chrisulm

Trying to provide a sample code.

Check if this helps.

Selecting a drop down list in a web page using VBA.
HTML Source code.

Code:
<span class='btn-group'>
  <button id='str_listing-btn' name='str_listing-btn' type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown' data-value='For Sale'>
    For Sale
    <span class='caret' style='margin-left:5px;'>
    </span>
  </button>
  <ul class='dropdown-menu wptk_crud_dropdown' id='str_listing' data-value='str_listing' role='menu'>
    <li>
      <a href='#' data-value='For Sale'>For Sale</a>
    </li>
    <li>
      <a href='#' data-value='For Rent'>For Rent</a>
    </li>
    <li>
      <a href='#' data-value='Wanted To Buy'>Wanted To Buy</a>
    </li>
    <li>
      <a href='#' data-value='Wanted To Rent'>Wanted To Rent</a>
    </li>
  </ul>
</span

VBA code.


Code:
Sub NavigateIt()
    Dim oIE As Object

    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.navigate ("SITE NAME")'' Change site name as per your requirment.
    oIE.Visible = True

    Do
        DoEvents
    Loop Until oIE.ReadyState = 4

    Set AvailableLinks = oIE.document.getelementbyid("list-listing").getelementsbytagname("a")

    For Each cLink In AvailableLinks
        If cLink.innerhtml = "For Rent" Then
            cLink.Click
        End If
    Next cLink

End Sub

Let me know any challenges..Happy to help you.
 
Hello chrisulm

Trying to provide a sample code.

Check if this helps.

Selecting a drop down list in a web page using VBA.
HTML Source code.

Code:
<span class='btn-group'>
  <button id='str_listing-btn' name='str_listing-btn' type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown' data-value='For Sale'>
    For Sale
    <span class='caret' style='margin-left:5px;'>
    </span>
  </button>
  <ul class='dropdown-menu wptk_crud_dropdown' id='str_listing' data-value='str_listing' role='menu'>
    <li>
      <a href='#' data-value='For Sale'>For Sale</a>
    </li>
    <li>
      <a href='#' data-value='For Rent'>For Rent</a>
    </li>
    <li>
      <a href='#' data-value='Wanted To Buy'>Wanted To Buy</a>
    </li>
    <li>
      <a href='#' data-value='Wanted To Rent'>Wanted To Rent</a>
    </li>
  </ul>
</span

VBA code.


Code:
Sub NavigateIt()
    Dim oIE As Object

    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.navigate ("SITE NAME")'' Change site name as per your requirment.
    oIE.Visible = True

    Do
        DoEvents
    Loop Until oIE.ReadyState = 4

    Set AvailableLinks = oIE.document.getelementbyid("list-listing").getelementsbytagname("a")

    For Each cLink In AvailableLinks
        If cLink.innerhtml = "For Rent" Then
            cLink.Click
        End If
    Next cLink

End Sub

Let me know any challenges..Happy to help you.

Would the following code need to reference "str_listing" rather than "list-listing"?
Code:
Set AvailableLinks = oIE.document.getelementbyid("list-listing").getelementsbytagname("a")
 
Back
Top