Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在网站上的按钮事件之间等待_Vb.net_Webbrowser Control - Fatal编程技术网

Vb.net 在网站上的按钮事件之间等待

Vb.net 在网站上的按钮事件之间等待,vb.net,webbrowser-control,Vb.net,Webbrowser Control,我想在两个单击事件之间等待,因为第二个事件取决于第一个事件的结果 我的代码表明: '************************************************************************** 'Adding piece number to the webbrowser control '26/12/2019 Kris Bauwens '********************************************

我想在两个单击事件之间等待,因为第二个事件取决于第一个事件的结果

我的代码表明:

    '**************************************************************************
    'Adding piece number to the webbrowser control
    '26/12/2019 Kris Bauwens
    '**************************************************************************
    Web.Document.GetElementById("hwbOrPiece").InnerText = txtSID.Text
    Web.Document.GetElementById("hwbOrPiece").RemoveFocus()
    SearchHWB()

Private Sub SearchHWB()
    '**************************************************************************
    'Search if the piece number exist, if so look for the history
    '27/12/2019 Kris Bauwens
    '**************************************************************************
    Dim HtmlElementcol As HtmlElementCollection = Web.Document.GetElementsByTagName("button")
    For Each elem As HtmlElement In HtmlElementcol
        If elem.InnerText = "search " Then
            elem.Focus()
            'Invoke event
            elem.InvokeMember("click")
            Thread.Sleep(3000) ''''''''''''''''''''''''-> not really working
            Do While blnFind = False
                SearchHistory()
            Loop
            Exit For
        End If
    Next
    blnFind = False
End Sub

Private Function SearchHistory() As Boolean
    '**************************************************************************
    'Look for the history
    '27/12/2019 Kris Bauwens
    '**************************************************************************
    Dim HtmlElementcol As HtmlElementCollection = Web.Document.GetElementsByTagName("button")
    For Each elem As HtmlElement In HtmlElementcol
        Debug.Print(elem.InnerText)
        If elem.InnerText = "SD History " Then
            elem.Focus()
            'Invoke event
            elem.InvokeMember("click")
            blnFind = True
            Exit For
        End If
    Next
    Return blnFind
End Function
我用“线”试过了,但速度很快。系统已从第二个事件开始,而不是等待第一个事件。它甚至不需要等待innertext执行


如何解决这个问题?

我用旧的应用程序.DoEvents()替换了Thread.Sleep(直到1998年才使用Visual Basic)
我不喜欢,还有其他建议吗?

这不是它的工作原理。在第一个事件中,您设置了一个
布尔
标志以指示该事件已发生。在第二个事件中,检查该标志。你知道,就像在现实生活中一样。我尝试了几件事…当你点击按钮元素时,页面会完全刷新吗?如果是这样,您可以在SearchHistory的documentcomplete事件中抛出逻辑。不过,我想你是想操纵别人的页面吧?使用Fiddler和发送/接收原始数据可能比通过web控件操作DOM更容易。这样你会得到更加一致的结果。这不是一次完全的刷新。我也用VBA编程,我得到了Javascript/角度错误消息。