Click here to Skip to main content
13,549,436 members
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 4 Jan 2011
Licenced CPOL

Automation Tool for Web Activities

, 5 Jan 2011
Rate this:
Please Sign up or sign in to vote.
You can reduce human efforts by automating the work.


Following my post about Live Score [Cricket] on GIT, I got a request to publish the code for doing the same. And here I am, starting with my first article. I hope that you will find it useful in one or the other way.


There is nothing much to be done, but it is found that not many of us know the way - how to do it. I am showing you how you can update "your" post automatically in CodeProject. There can be many other uses of it, but I recently used it for this task.

Using the Code

It consist of 2 steps:

  1. Get the content to be posted
  2. Post the content

This code is required to know whether the page is loaded.

Dim proceed As Boolean

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
  Handles WebBrowser1.DocumentCompleted
  proceed = True
End Sub

And here is the function that can be used to browse a page, or to post some data to a page.

Public Sub FillForm(ByRef wbrowser As System.Windows.Forms.WebBrowser, _
  ByVal url As String, Optional ByVal keys() As String = Nothing, _
  Optional ByVal values() As String = Nothing, _
  Optional ByVal submit As String = "")
  Dim obj As HtmlElement
  Dim objcol As System.Windows.Forms.HtmlElementCollection

  proceed = False
  While Not proceed
  End While
  proceed = False

  If keys Is Nothing Or values Is Nothing Then Exit Sub

  If keys.Length = values.Length Then
    For i As Integer = 0 To keys.Length - 1
      obj = wbrowser.Document.GetElementById(keys(i))
      If obj IsNot Nothing Then obj.SetAttribute("value", values(i))

    If submit <> "" Then
      If submit = "true" Then
        objcol = wbrowser.Document.GetElementsByTagName("input")
        For Each objx In objcol
          If objx.GetAttribute("Type").ToLower = "submit" Then
            obj = objx
            Exit For
          End If
        obj = wbrowser.Document.GetElementById(submit)
      End If
      If obj IsNot Nothing Then
      End If
    End If
  End If
  proceed = False
End Sub

To browse a page, you can use this function like:

FillForm(WebBrowser1, "") 

My application uses Yahoo Cricket to get the latest score. So I get the page:

FillForm(WebBrowser1, _  

When the page is loaded, I have to look for the score. I checked the page source for that and found that tab1 and header-main contains the main score.

So I use the following to get the score content:

Dim content As String = WebBrowser1.Document.GetElementById_
	("header-main").InnerText.Trim & vbCrLf & vbCrLf & _

This is how I get the content to be posted.

Now we have to post it to CodeProject. For that, I get the edit link of my post, which is -

Now with the above function, it is a piece of cake to get it posted.

FillForm(WebBrowser1, My.Settings.EditURL, New String() _
	{"ctl00_MC_Subject", "ctl00_MC_ContentText_MessageText"}, _
	New String() {"Live Score [Cricket]", content}, "ctl00_MC_submit")

My.Settings.EditURL contains the edit URL of my post. Again with page source, I found the IDs of the required controls:

  • ctl00_MC_Subject
  • ctl00_MC_ContentText_MessageText
  • ctl00_MC_submit

As you can see, keys contains the control IDs which are to be edited and values contain the values for those controls in the same order. submit is the ID of the button to post the message. I have a special case for this parameter, if submit="true", then it finds the button on the page and clicks it. This can be useful when there is just one button on page having no ID.

It works as follows: It looks for controls in the keys and assigns them values from values. After assigning all the values, it looks for the submit button to post it.

Points of Interest

This can be used in many ways. This is just what and how you can do it. Just a wise word - use it for good, don't use it to spam.

I know that this doesn't deal with any message box, or script error coming from page. And there can be many other cases to be considered.

There are a wide scope of modifications, but so far, I am fine with this one function only. It worked whenever I required it. Still, your suggestions are welcome. Please keep me posted if you find a good use of it, or a modification.


  • No changes have been made to the code at this stage (Jan 2011)
  • [201101051220] Included code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Prerak Patel
Software Developer
India India
Working since 2006 on VBA, VB6, VB.Net, C#, ASP.Net, MSSQL

  • Courage is not the absence of fear, but rather the judgement that something is more important than fear.
  • The fear of suffering is worse than the suffering itself.
  • People need not fear the unknown if they are capable of achieving what they need and want.
  • Every blessing ignored becomes a curse.
  • Sometimes what's in your head isn't as crazy as you think.
  • We never really grow up, we only learn how to act in public.
  • You can make very bad teams with very good individuals.
  • Admitting mistakes means you have a sense of responsibility in your actions and that shows you are more matured than almost anyone. -Nithin

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Harmanjeet Singh20-Sep-11 3:45
memberHarmanjeet Singh20-Sep-11 3:45 
GeneralMy vote of 5 Pin
Prasanta_Prince25-May-11 21:51
memberPrasanta_Prince25-May-11 21:51 
GeneralMy vote of 5 Pin
thatraja5-Apr-11 7:55
mvpthatraja5-Apr-11 7:55 
Generalnice - have 5 Pin
Pranay Rana25-Jan-11 2:02
memberPranay Rana25-Jan-11 2:02 
GeneralMy vote of 5 Pin
Abhinav S22-Jan-11 22:59
mvpAbhinav S22-Jan-11 22:59 
GeneralWould be better Pin
Richard MacCutchan21-Jan-11 3:12
mvpRichard MacCutchan21-Jan-11 3:12 
GeneralMy Vote of 5 Pin
RaviRanjankr18-Jan-11 18:15
memberRaviRanjankr18-Jan-11 18:15 
GeneralRe: My Vote of 5 Pin
Prerak Patel18-Jan-11 20:26
memberPrerak Patel18-Jan-11 20:26 
GeneralMy vote of 5 Pin
MDNadeemAkhter11-Jan-11 1:28
memberMDNadeemAkhter11-Jan-11 1:28 
GeneralRe: My vote of 5 Pin
Prerak Patel11-Jan-11 3:36
memberPrerak Patel11-Jan-11 3:36 
GeneralMy vote of 5 Pin
prasad025-Jan-11 15:08
memberprasad025-Jan-11 15:08 
Generalanother way... [modified] Pin
Selvin5-Jan-11 2:01
memberSelvin5-Jan-11 2:01 
GeneralRe: another way... Pin
Prerak Patel5-Jan-11 2:05
memberPrerak Patel5-Jan-11 2:05 
GeneralRe: another way... Pin
Selvin5-Jan-11 4:37
memberSelvin5-Jan-11 4:37 
GeneralMy vote of 5 Pin
SChristmas5-Jan-11 0:10
memberSChristmas5-Jan-11 0:10 
GeneralMy vote of 5 Pin
maB_J5-Jan-11 0:02
membermaB_J5-Jan-11 0:02 
GeneralRe: My vote of 5 Pin
Prerak Patel5-Jan-11 0:03
memberPrerak Patel5-Jan-11 0:03 
GeneralRe: My vote of 5 Pin
maB_J5-Jan-11 0:06
membermaB_J5-Jan-11 0:06 
GeneralRe: My vote of 5 Pin
Richard MacCutchan21-Jan-11 3:06
mvpRichard MacCutchan21-Jan-11 3:06 
GeneralRe: My vote of 5 Pin
maB_J21-Jan-11 7:05
membermaB_J21-Jan-11 7:05 
GeneralRe: My vote of 5 Pin
Richard MacCutchan21-Jan-11 9:11
mvpRichard MacCutchan21-Jan-11 9:11 
GeneralGood One Pin
maB_J5-Jan-11 0:02
membermaB_J5-Jan-11 0:02 
GeneralRe: Good One Pin
Prerak Patel5-Jan-11 0:08
memberPrerak Patel5-Jan-11 0:08 
GeneralRe: Good One Pin
maB_J5-Jan-11 0:10
membermaB_J5-Jan-11 0:10 
GeneralGood article prerak, But Pin
Hiren Solanki4-Jan-11 23:54
memberHiren Solanki4-Jan-11 23:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 5 Jan 2011
Article Copyright 2011 by Prerak Patel
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid