Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i was trying to make a free microsoft word plugin in vb.net. It automatically fills a web form. The main problem with the plugin is that it uses web browser control and once it has filled a form it will need to navigate another form. The form can only be filled once it has completely been loaded.

so my approach is
1. navigate to first site when form loads

<big>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       WebBrowser1.Navigate("http://google.com")
   End Sub</big>


2. use an integer i and use if statements to check which form to fill :

<big>Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If (i = 1) Then
            WebBrowser1.Document.GetElementById("username").SetAttribute("value", "elvin")
            WebBrowser1.Document.GetElementById("password").SetAttribute("value", "1111111")
            WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
            i = 2
        ElseIf (i = 2) Then
            WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
            WebBrowser1.Document.GetElementById("content").SetAttribute("value", "111111")
            WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fgddferre")
            WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
            i = 3
            Timer1.Start()
        ElseIf (i = 3) Then
            Timer1.Stop()
            WebBrowser1.Document.GetElementById("loginTextBlock_uname").SetAttribute("value", "elvin")
            WebBrowser1.Document.GetElementById("loginTextBlock").SetAttribute("value", "11111")
            WebBrowser1.Document.GetElementById("nowwhat").InvokeMember("click")
            i = 4
        ElseIf (i = 4) Then
            WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
            WebBrowser1.Document.GetElementById("content").SetAttribute("value", "11111")
            WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fghfghfgh")
            WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
            i = 5
            Timer1.Start()
        ElseIf (i = 5) Then
            WebBrowser1.Document.GetElementById("user").SetAttribute("value", "rfgjhfhj")
            WebBrowser1.Document.GetElementById("pass").SetAttribute("value", "566788989")
            WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
            i = 6
        End If
    End Sub
</big>



3. this is the main step. you see when main form loads, i=1 so browser goes to google.com (first form), when form is completely loaded, itchecks for value of i. Since i=1, it fills google. After filling and continuing i=2 and browser goes to my personal account page. This means browser again loads the document. Now i=2, so it fills my personal detalis. Now the timer starts. Since i=3, browser navigates to second site and fills the details.

<big> Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If (i = 3) Then
            WebBrowser1.Navigate("http://blogger.com")
        ElseIf (i = 5) Then
            WebBrowser1.Navigate("http://www.yahoo.com/")
        End If
    End Sub</big>


now the problem arises. The browser does not go to the third site. Once the timer has been stopped and started, the following code does not goto the elseif part (i.e. i=5) why is that so?
Posted
Updated 19-Jul-10 3:15am
v3
Comments
Christian Graus 19-Jul-10 17:20pm    
What a disaster. Be careful to say that 'xxx does not work' when people use it all over the world, you should assume your code is broken, as it plainly is.

what are you trying to do? this will never act like a timer it ons fires on form load

have a look at this example for timers Timer Example^
 
Share this answer
 
v2
Comments
amit_upadhyay 19-Jul-10 9:16am    
sorry, first time i posted incomplete question.
Set a breakpoint on the second Timer1.Start(). See if it even gets inside the ElseIf (i = 4) Then block.

Why even use a timer? I think you could just take the timer out, perform the click, and when the postback finishes add another step to redirect:
VB
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    If (i = 1) Then
        WebBrowser1.Document.GetElementById("username").SetAttribute("value", "elvin")
        WebBrowser1.Document.GetElementById("password").SetAttribute("value", "1111111")
        WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
        i = 2
    ElseIf (i = 2) Then
        WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
        WebBrowser1.Document.GetElementById("content").SetAttribute("value", "111111")
        WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fgddferre")
        WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
        i = 3
    ElseIf (i = 3) Then
        WebBrowser1.Navigate("http://blogger.com")
        i = 4
    ElseIf (i = 4) Then
        WebBrowser1.Document.GetElementById("loginTextBlock_uname").SetAttribute("value", "elvin")
        WebBrowser1.Document.GetElementById("loginTextBlock").SetAttribute("value", "11111")
        WebBrowser1.Document.GetElementById("nowwhat").InvokeMember("click")
        i = 5
    ElseIf (i = 5) Then
        WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
        WebBrowser1.Document.GetElementById("content").SetAttribute("value", "11111")
        WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fghfghfgh")
        WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
        i = 6
    ElseIf (i = 6) Then
        WebBrowser1.Navigate("http://www.yahoo.com/")
        i = 7
    ElseIf (i = 7) Then
        WebBrowser1.Document.GetElementById("user").SetAttribute("value", "rfgjhfhj")
        WebBrowser1.Document.GetElementById("pass").SetAttribute("value", "566788989")
        WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
        i = 8
    End If
End Sub
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900