0

我正在尝试创建一个脚本来导航到网页,等待元素加载,然后从新页面收集元素。就目前而言,这个脚本在它应该等待的时候直接运行:

Do Until AxWebBrowser1.ReadyState = WebBrowserReadyState.Complete 

处理后:

htmldoc.getElementsByName("GetCase").item(0).click() 'click the submit button

我立即得到第二个子的消息框弹出窗口,而实际上页面还没有完成加载。我该如何解决这个问题并让脚本等到页面准备好,然后制作 htmldoc = axwebbrowser1.document

Private Sub GetCase()

    htmldoc = AxWebBrowser1.Document.frames("top").document 'set the top frame to be searched for

    setval = htmldoc.getElementsByName("caseNum").item(0) 'grab the input name for contracts

    setval.value = TextBox1.Text 'set the textbox value into the web form input
    TextBox1.Clear()

    htmldoc.getElementsByName("GetCase").item(0).click() 'click the submit button


    Do Until AxWebBrowser1.ReadyState = WebBrowserReadyState.Complete 'do events until it is complete
        Application.DoEvents()
    Loop


    If ComboBox1.Text = "MM" Then
        Gather()

    End If

End Sub



Private Sub Gather()
    Do Until AxWebBrowser1.ReadyState = WebBrowserReadyState.Complete 'do events until it is complete
        Application.DoEvents()
    Loop

    htmldoc = AxWebBrowser1.Document
    MessageBox.Show("got elements")


End Sub
4

1 回答 1

0

在 click() 之后,在检查 ReadyState 之前,您需要等待一段时间,即 2 秒,以允许浏览器响应单击事件。就像是:

for i as integer = 0 to 10
    Sleep(200)
    Application.Doevent()
next

然后检查就绪状态

于 2012-10-26T14:38:22.380 回答