1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Etape 1: Utiliser WebBrowser control pour charger la page web
WebBrowser1.Navigate("http://www.website.com/login.aspx")
System.Threading.Thread.Sleep(2000) ' Attendre 2 secondes le temps de chargement
' Etape 2: Remplir les input username et password
Dim theElementCollection As HtmlElementCollection
theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If controlName = "UserNameTextBox" Then
curElement.SetAttribute("Value", "Mettre ton Username ici")
ElseIf controlName = "PasswordTextBox" Then
curElement.SetAttribute("Value", "Mettre ton Password ici")
'En plus, on peut avoir la valeur de l'element value comme ceci:
'MessageBox.Show(curElement.GetAttribute("Value"))
End If
Next
' Etape 3: Cliquer automatiquement sur le bouton Login
theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals("Login") Then
curElement.InvokeMember("click")
' Appeler la methode click du bouton Login
End If
Next
End Sub
End Class |
Partager