VB.NET WebBrowser click on the button

I am working on a small VB.NET project that automatically fills in the fields on the Yahoo registration page. Is there a way to click on the "Check" button and see if the entered identifier is in order or not?

Something like, if the entered identifier is OK, go ahead with filling in the field, if not, try another identifier and click the "Check" button again.

+3
source share
2 answers

The web browser control allows you to access the elements of the web page, and you can call methods on them, so something simple like this will push a button:

webBrowser1.Document.All("yidHelperBtn").InvokeMember("click");
+5

1000 . :

Dim CheckButton, yahooId As HtmlElement
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _ 

WebBrowser1.DocumentCompleted

    yahooId = WebBrowser1.Document.GetElementById("yahooid")
    CheckButton = WebBrowser1.Document.GetElementById("yidHelperBtn")

    yahooId.InnerText = "testID" 'Replace testID by the ID you want

    Timer1.Start() 'Starts the timer: within 1000 ms (1 s). It will execute the Timer1_Tick sub.

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    CheckButton.Focus() 'Give the check button the focus
    SendKeys.Send("{ENTER}") 'Causes the validation of the check button
    Timer1.Stop() 'Stops the timer 
End Sub

, , , Enter WebBrowser1_DocumentCompleted.

, . , , .

0

Source: https://habr.com/ru/post/1792555/


All Articles