webbrowser automating
im going to post a bunch of code on webbrowser automating that i used to use when i just started learnign before i got into webrequest
Click A Button
IF ID Exists
Click Button Just By Value Of It
Click Check box
Click all Check box's with same value
Fill Textbox In Webbrowser
Get Text From Textbox In Webbrowser
Stop IE Pop ups
Check URL
webbrowser contains
Webbrowser status
Show Page Source
Download Page
Click A Button
Code:
webbrowser1.Document.All("Button ID").InvokeMember("click")
Code:
If WebBrowser1.Document.All("ID") Is Nothing Then
Else
MsgBox("ID exsits")
End If
Code:
Private Function GetBtnByValue(ByVal value As String) As HtmlElement
For Each d As HtmlElement In Webbrowser1.Document.GetElementsByTagName("input")
If (d.GetAttribute("type").ToLower = asd.Text Or d.GetAttribute("type").ToLower = "submit") Then
If (d.GetAttribute("value") = value) Then
Return d
Exit For
End If
End If
Next
End Function
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
GetBtnByValue("go").InvokeMember("Click")
End Sub
Code:
Dim outer As String = WebBrowser1.Document.All("PersistentCookie").OuterHtml
WebBrowser1.Document.All("Check Box ID").OuterHtml = outer.Remove(outer.Length - 2) + " checked>"
Code:
For Each InputBx As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If (InputBx.GetAttribute("type").ToLower = "radio") AndAlso (InputBx.GetAttribute("value").ToLower = "Value Of Check Box") Then
InputBx.InvokeMember("Click")
End If
Next
Code:
For Each HTMLele As HtmlElement In WebBrowser1.Document.All
If HTMLele.Name = "ID" Then
HTMLele.SetAttribute("value", "someemail@somewhere.comValue")
End If
Next
Code:
Dim text As String = WebBrowser1.Document.All("Textbox ID).GetAttribute("value")
TextBox1.Text = text
Code:
WebBrowser1.ScriptErrorsSuppressed = True
Code:
If WebBrowser1.Url.ToString = "URL" Then
Code:
If WebBrowser1.DocumentText.Contains("Phrase") Then
Else
End If
Code:
TextBox1.Text = WebBrowser1.StatusText
Code:
TextBox1.Text = webBrowser.Document.body.innerHTML
Code:
Dim MyWebClient As New System.Net.WebClient()
TextBox1.Text = MyWebClient.DownloadString("URL")

