【问题标题】:Fill in the website form with drop-down menu with VBA使用 VBA 填写带有下拉菜单的网站表单
【发布时间】:2020-05-04 15:57:01
【问题描述】:

在 Excel 中编写以下 VBA 宏:

Sub compile()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

IE.Navigate "www.google.it"
IE.Visible = True

Do While IE.Busy
    DoEvents
Loop

IE.document.getElementById("Civico").Value = "1"

End Sub

“门牌号”字段未填写,我真的不知道如何填写。有人能帮我吗?谢谢!

【问题讨论】:

    标签: excel vba internet-explorer-11


    【解决方案1】:

    我认为您不能选择下拉列表值,因为它没有被初始化。我们需要从“VCinputLoc”中选择值,以便显示“VCinputCivico”的下拉列表。您可以模拟按键而不是设置值,并在代码等待下拉初始化中添加一些等待。

    代码示例:

    Sub compile()
    
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    
    IE.Navigate "https://fibra.planetel.it"
    IE.Visible = True
    
    Do While IE.Busy
        DoEvents
    Loop
    
    IE.document.getElementById("VCinputLoc").Focus
    IE.document.getElementById("VCinputLoc").Value = "ROMA"
    Application.SendKeys "{ENTER}"
    Application.Wait (Now + TimeValue("00:00:02"))
    IE.document.getElementsByClassName("autocomplete-suggestion")(0).Click
    IE.document.getElementById("VCinputIndirizzo").Focus
    IE.document.getElementById("VCinputIndirizzo").Value = "Piazza Del Campidoglio"
    Application.Wait (Now + TimeValue("00:00:05"))
    IE.document.getElementById("VCinputCivico_chosen").getElementsByTagName("a")(0).Focus
    Application.SendKeys "{DOWN}"
    Application.SendKeys "1"
    Application.SendKeys "{DOWN}"
    Application.SendKeys "{ENTER}" 'the last step can't enter the value, you could research more and I'll also continue to research
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2017-05-10
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 2022-01-13
      • 2018-12-31
      • 1970-01-01
      相关资源
      最近更新 更多