Vba 无法单击网页中某些灰显的提交按钮

Vba 无法单击网页中某些灰显的提交按钮,vba,web-scraping,internet-explorer-11,Vba,Web Scraping,Internet Explorer 11,我在vba中创建了一个脚本,使用IE在网页中填写少量输入,以填充特定项目 以下是我希望脚本执行的步骤: 从登录页选择购买砖块 输入年龄(35岁)和国家(英国),然后单击提交按钮 在下一页中,输入唯一标识号 对于元素/设计编号框中的乐高积木,例如4219725 我的脚本可以满足前两个要求(除了单击submit按钮)。即使输入框已正确填写,“提交”按钮仍会灰显。单击submit按钮后,我希望满足第三个要求 我的尝试: Sub GetDetails() Dim IE As New Inter

我在vba中创建了一个脚本,使用IE在网页中填写少量输入,以填充特定项目

以下是我希望脚本执行的步骤:

  • 从登录页选择
    购买砖块
  • 输入年龄(35岁)和国家(英国),然后单击提交按钮
  • 在下一页中,输入唯一标识号 对于
    元素/设计编号
    框中的乐高积木,例如
    4219725
  • 我的脚本可以满足前两个要求(除了单击submit按钮)。即使输入框已正确填写,“提交”按钮仍会灰显。单击
    submit
    按钮后,我希望满足第三个要求

    我的尝试:

    Sub GetDetails()
        Dim IE As New InternetExplorer, I As Long
        Dim Html As HTMLDocument, post As Object, ageInput As Object
    
        With IE
            .Visible = True
            .navigate "https://www.lego.com/en-gb/service/replacementparts"
            While .Busy Or .readyState < 4: DoEvents: Wend
            Set Html = .document
            Html.querySelectorAll(".arrow-list-info")(2).Click
    
            Do: Set ageInput = Html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
            ageInput.Focus
            ageInput.innerText = 30
    
            Do: Set post = Html.querySelector("select[ng-model='country']"): DoEvents: Loop While post Is Nothing
            For I = 0 To post.Length - 1
                If InStr(post(I).innerText, "United Kingdom") > 0 Then post(I).Selected = True: Exit For
            Next I
        End With
    End Sub
    
    Sub-GetDetails()
    Dim IE作为新的InternetExplorer,我希望
    将Html设置为HTMLDocument、post设置为对象、ageInput设置为对象
    与IE
    .Visible=True
    .导航“https://www.lego.com/en-gb/service/replacementparts"
    当.Busy或.readyState<4:DoEvents:Wend时
    设置Html=.document
    querySelectorAll(“.arrow list info”)(2)。单击
    Do:Set-ageInput=Html.querySelector(“输入[id*='How old']”):DoEvents:Loop While-ageInput为Nothing
    ageInput.Focus
    ageInput.innerText=30
    Do:Set post=Html.querySelector(“选择[ng model='country']”):DoEvents:Loop While post Is Nothing
    对于I=0到post.Length-1
    如果InStr(post(I).innerText,“英国”)>0,则post(I).Selected=True:退出
    接下来我
    以
    端接头
    

    如何激活灰显的提交按钮以启动对其的单击?

    向选择元素添加更改事件

    Option Explicit
    Public Sub GetDetails()
        Dim IE As New InternetExplorer, html As HTMLDocument, ageInput As Object
    
        With IE
            .Visible = True
            .Navigate2 "https://www.lego.com/en-gb/service/replacementparts"
            While .Busy Or .readyState < 4: DoEvents: Wend
            Set html = .document
            Dim event_onChange As Object
            Set event_onChange = .document.createEvent("HTMLEvents")
            event_onChange.initEvent "change", True, False
            html.querySelectorAll(".arrow-list-info")(2).Click
    
            Do: Set ageInput = html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
            ageInput.innerText = 30
            html.querySelector("[label='United Kingdom").Selected = True
            IE.document.querySelector("select").dispatchEvent event_onChange
            IE.document.querySelector("[ng-click='startFlow()'").Click
    
            Do: Loop While IE.document.querySelectorAll("[ng-model=itemNumber]").Length = 0
            IE.document.querySelector("[ng-model=itemNumber]").Focus
            IE.document.querySelector("[ng-model=itemNumber]").Value = "4219725"
            Stop
        End With
    End Sub
    
    选项显式
    公共子目录详细信息()
    Dim IE作为新的InternetExplorer,html作为HTMLDocument,ageInput作为对象
    与IE
    .Visible=True
    .导航2“https://www.lego.com/en-gb/service/replacementparts"
    当.Busy或.readyState<4:DoEvents:Wend时
    设置html=.document
    Dim事件更改为对象
    Set event_onChange=.document.createEvent(“HTMLEvents”)
    event_onChange.initEvent“change”,True,False
    querySelectorAll(“.arrow list info”)(2)。单击
    Do:Set-ageInput=html.querySelector(“输入[id*='How old']”):DoEvents:Loop While-ageInput为Nothing
    ageInput.innerText=30
    html.querySelector(“[label='United Kingdom”).Selected=True
    例如,document.querySelector(“select”).dispatchEvent事件更改
    IE.document.querySelector(“[ng click='startFlow()”)。单击
    Do:在IE.document.querySelectorAll(“[ng model=itemNumber]”时循环。长度=0
    IE.document.querySelector(“[ng model=itemNumber]”)。焦点
    IE.document.querySelector(“[ng model=itemNumber]”)。Value=“4219725”
    停止
    以
    端接头
    
    按钮现在似乎处于活动状态,但没有执行单击。我尝试了此
    Html.querySelector(“按钮[class*='pull-right']”)
    。我甚至手动单击了该按钮,但运气不佳。改为添加更改事件。是的,单击现在工作正常。我有最后一个要求(第3项)你可以在我的帖子中看到我很满意。谢谢你和我在一起。很高兴听到这个消息。请继续回答有趣的问题。