Results 1 to 6 of 6

Thread: webbrowser problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    webbrowser problem

    Code:
    WebBrowser1.Navigate "http://abc.com"
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
    
    WebBrowser1.Document.All("username").Value = "admin"
    WebBrowser1.Document.All("clickbutton").clicked 
    
    WebBrowser1.Navigate "http://xyz.com"
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
    
    WebBrowser1.Document.All("username").Value = "admin"
    WebBrowser1.Document.All("clickbutton").clicked

    I want to login in two sites on a single command button click event and the problem is that as soon this command run

    WebBrowser1.Document.All("clickbutton").clicked

    it execute next line either the previous line is succesffully executed or not......

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: webbrowser problem

    maybe you need to wait for readystate complete again, before navigating to next page
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: webbrowser problem

    i have tried but not working

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webbrowser problem

    You should use the _DocumentComplete Event to do what you want
    Code:
    Dim NoReEntry1 As Boolean
    Dim NoReEntry2 As Boolean
      '
      '
    Private Sub Command1_Click()
     WebBrowser1.Navigate "http://abc.com"
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(....., URL As Variant)
     If URL = "http://abc.com" Then
       If NoReEntry1 <> True Then 
         NoReEntry1 = True
         WebBrowser1.Document.All("username").Value = "admin"
         WebBrowser1.Document.All("clickbutton").clicked 
         WebBrowser1.Navigate "http://xyz.com"
       End If   
     End If
    
     If URL = "http://xyz.com" Then
       If NoReEntry2 <> True Then
         NoReEntry2 = True
         WebBrowser1.Document.All("username").Value = "admin"
         WebBrowser1.Document.All("clickbutton").clicked 
       End If   
     End If
    End Sub
    Last edited by jmsrickland; Feb 13th, 2009 at 11:27 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: webbrowser problem

    Code:
    Dim NoReEntry1 As Boolean
    Dim NoReEntry2 As Boolean
    
    Private Sub Command1_Click()
    web1.Navigate "http://abc.com"
    web1.Navigate "http://xyz.com"
    End Sub
    
    Private Sub web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If URL = "http://abc.com" Then
       If NoReEntry1 <> True Then
     NoReEntry1 = True
     WebBrowser1.Navigate "http://abc.com"
       End If
     End If
    
     If URL = "http://xyz.com" Then
       If NoReEntry2 <> True Then
         NoReEntry2 = True
    WebBrowser1.Navigate "http://xyz.com"
     End If
     End If
    
    
    End Sub
    as soon as i run this code it is not showing me http://abc.com it direct go to xyz.com

    i want that firstly abc.com totally load in webbrowser and after that xyz.com load in webbrowser
    Last edited by CatchItBaby; Feb 13th, 2009 at 04:12 PM.

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webbrowser problem

    You are really making a mess out of this. You cannot navigate to two different sites in the same Command event like you are doing.

    What you are trying to do isn't going to work because as soon as abc.com loads you turn right around and load xyz.com. You know the browser cannot show two sites at the same time. You need to load abc.com and pause it for awhile (use some kind of timing method or set a switch as to when it is OK to load xyz) before you load xyz.com. At least wait until your login has finished with abc before you navigate to xyz.

    What you are doing is like clicking on a link and then click on another link at the flash of an eye.
    Last edited by jmsrickland; Feb 13th, 2009 at 04:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width