Html 填写webform时,Excel VBA从网站下拉列表中选择选项

Html 填写webform时,Excel VBA从网站下拉列表中选择选项,html,excel,vba,Html,Excel,Vba,我正在尝试使用VBA excel自动化此网站。我在一个点上被击中,我必须从下拉框中选择值。我是非常新的VBA和这是我的第一个这样的项目。这是我用来选择值的代码 Sub automaticformfilling_ASDA() Dim ie As Object Set ie = CreateObject("internetexplorer.application") 'to make sure that the website is properly loaded

我正在尝试使用VBA excel自动化此网站。我在一个点上被击中,我必须从下拉框中选择值。我是非常新的VBA和这是我的第一个这样的项目。这是我用来选择值的代码

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
半自动填充_ASDA()
模糊的物体
设置ie=CreateObject(“internetexplorer.application”)
'以确保网站已正确加载
与ie
.Visible=True
.导航“https://www.argos-pet-insurance.com/quoteAndBuy.do?e=e1s1&curPage=captureDetails&rakT=1510852044896.1391473424.994101.1731.881880349.846|tsid:9904“
忙着干吧
多芬特
环
请稍等。readyState 4
多芬特
环
以
Set Title=i.e.document.getElementById(“yourDetailsPolicyHolderTitle”)
对于Title.Options.Length的i=1
如果Title.Options(i).Text=“Mrs”,则
退出
如果结束
接下来我
端接头
以下是该部分的HTML:

<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>

请选择
博士
未击中
先生
夫人
太太

根据SJR的评论以及我在您的代码中发现的一个打字错误,如果您用此代码替换代码,那么它应该可以工作:

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
半自动填充_ASDA()
模糊的物体
设置ie=CreateObject(“internetexplorer.application”)
'以确保网站已正确加载
与ie
.Visible=True
.导航“https://www.argos-pet-insurance.com/quoteAndBuy.do?e=e1s1&curPage=captureDetails&rakT=1510852044896.1391473424.994101.1731.881880349.846|tsid:9904“
忙着干吧
多芬特
环
请稍等。readyState 4
多芬特
环
以
Set Title=ie.document.getElementById(“yourDetailsPolicyHolderTitle”)
Title.selectedIndex=4
端接头
您输入了i.e.document.getElementByID,其中应该有ie.document。

如果要选择“Mrs”,只需使用
Title.selectedindex=4