我正在尝试创建一个脚本来导航到网页,等待加载元素,然后从新页面收集元素。按照目前的情况,这个脚本应该在等待时直接运行:
Do Until AxWebBrowser1.ReadyState = WebBrowserReadyState.Complete
进行处理:
htmldoc.getElementsByName("GetCase").item(0).click() 'click the submit button
我立刻得到了第二个sub的消息框弹出窗口,而实际上页面还没有完成加载。我如何解释这一点,并让脚本等到页面准备好,然后制作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
答案 0 :(得分:0)
在click()之后,在检查ReadyState之前,您需要等待一段时间,即2秒,以允许浏览器响应click事件。类似的东西:
for i as integer = 0 to 10
Sleep(200)
Application.Doevent()
next
然后检查readystate