-1

I have tried both innerhtml and innertext, both of which matched my string "Missing Enrollment" but my .click function is not clicking the item inside the drop down menu.

I know that innertext matches the string I put because I used F8 to run through step by step and saw "Missing Enrollment" inside locals.

html code

What the page looks like

    Set AvailableLinks = IE.Document.getelementbyid("messageMessageTypeId")
    For Each cLink In AvailableLinks
        If cLink.innerhtml = "Missing Enrollment" Then
            cLink.Click
        End If
    Next cLink
    
jonathan
  • 13
  • 4
  • `getelementbyid` returns a single element, not a collection you can loop over. Maybe you want `For Each cLink In AvailableLinks.Options` – Tim Williams Sep 28 '20 at 06:33
  • Does this answer your question? [Automate IE via Excel to fill in a dropdown and continue](https://stackoverflow.com/questions/63294113/automate-ie-via-excel-to-fill-in-a-dropdown-and-continue) – Foxfire And Burns And Burns Sep 28 '20 at 07:21
  • I'm in favor of Tim Williams' comment. You can't loop over a single element. If you want to select one of the options of the dropdown list, you can set the index of it. For example, if you want to choose **Data Inquiry**, you can use `AvailableLinks.selectedIndex = 4`. I also find [a similar thread](https://stackoverflow.com/questions/47940672/excel-vba-select-option-from-website-dropdown-list-while-filling-webform) you can refer to. – Yu Zhou Sep 29 '20 at 02:19
  • @TimWilliams using .options was helpful thanks – jonathan Sep 29 '20 at 03:06
  • @YuZhou That link you sent me was helpful thanks – jonathan Sep 29 '20 at 03:06
  • Thanks for posting the solution below. You can also mark your answer as an accepted answer after 48hrs, when it is available to mark. It can help other community members in future in similar kind of issues. Thanks for your understanding. – Yu Zhou Sep 29 '20 at 03:15
  • @YuZhou Would there be a way for me to use the .click or mimic the act of clicking instead. I believe that the act of clicking makes a call to end point to retrieve some data that I need to use on the same page. In other words, clicking the first drop down list provides the second drop down lists to appear. Currently running the code does not allow that to happen because it does not mimic the click option – jonathan Oct 02 '20 at 02:00

1 Answers1

1

As Tim said, one of my problems was that I was looping over a single element. With the use of .options and .selectedindex I was able to select the item I want from my drop down box.

Set AvailableLinks = IE.Document.getelementbyid("messageMessageTypeId")
For i =1 To MsgT.options.Length
     If MSgT.options(i).Text = "option I want it to select" Then
          MsgT.selectedindex=i
          Exit For
     End if
Next i
jonathan
  • 13
  • 4