0

I am trying to automate this website using VBA excel. I am struck at a point where I have to select value from the dropdown box. I am very much new to VBA and tis is my 1st such project. this is what I have coded to select the value.

Sub automaticformfilling_ASDA()

    Dim ie As Object

    Set ie = CreateObject("internetexplorer.application")

    'to make sure that the website is properly loaded

    With ie
        .Visible = True
        .navigate "https://www.argos-pet-insurance.com/quoteAndBuy.do?e=e1s1&curPage=captureDetails&rakT=1510852044896.1391473424.994101.1731.881880349.846|tsid:9904"

        Do While .Busy
            DoEvents
        Loop

        Do While .readyState <> 4
            DoEvents
        Loop  
    End With

    Set Title = i.e.document.getElementById("yourDetailsPolicyHolderTitle")

    For i = 1 To Title.Options.Length
       If Title.Options(i).Text = "Mrs" Then
         Exit For
       End If
    Next i

End Sub

Here is the HTML of that section:

<select name="policyHolder.title" class="select-large" id="yourDetailsPolicyHolderTitle" data-di-field-id="policyHolderTitle">
   <option selected="selected" value="">Please select</option>
   <option value="NWA_PET_T5">Dr</option>
   <option value="NWA_PET_T3">Miss</option>
   <option value="NWA_PET_T1">Mr</option>
   <option value="NWA_PET_T2">Mrs</option>
   <option value="NWA_PET_T4">Ms</option>
</select>
1
  • If you want to select "Mrs" just use Title.selectedindex = 4. Commented Dec 22, 2017 at 12:18

1 Answer 1

1

As per the comment from SJR and also a typo I found in your code, if you replace your code with this then it should work:

Sub automaticformfilling_ASDA()

    Dim ie As Object

    Set ie = CreateObject("internetexplorer.application")

    'to make sure that the website is properly loaded

    With ie
        .Visible = True
        .navigate "https://www.argos-pet-insurance.com/quoteAndBuy.do?e=e1s1&curPage=captureDetails&rakT=1510852044896.1391473424.994101.1731.881880349.846|tsid:9904"

        Do While .Busy
            DoEvents
        Loop

        Do While .readyState <> 4
            DoEvents
        Loop
    End With

    Set Title = ie.document.getElementById("yourDetailsPolicyHolderTitle")
    Title.selectedIndex = 4
End Sub

You entered i.e.document.getElementByID, where you should have ie.document.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.