Page 2 of 2 FirstFirst 12
Results 41 to 48 of 48

Thread: using .getElementsByName

  1. #41
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: using .getElementsByName

    Well if thats in the main thread, you will hang your entire app permanently, as you can't sleep the thread and load the webpage asynchronously from the same thread. You'd need to create a new thread for that wait sub.

    vb Code:
    1. Dim nT As New Threading.Thread(AddressOf wait)
    2.         nT.Start()
    3.  
    4.  
    5.     Private Sub wait()
    6.         While WebBrowser1.ReadyState < 4
    7.             Threading.Thread.Sleep(100)
    8.         End While
    9.         '//next call after WebBrowser is finished loading
    10.     End Sub

    As for only doing it once, you need to narrow down when the procedure is run on the documentcompleted event. At the moment, whenever the document finishes loading it will run. Either slip in a global boolean that you set by default to true, on the documentcompleted event check if this is true or not, and if so run it and then set the value to false to prevent further execution.
    Last edited by J-Deezy; Oct 6th, 2010 at 09:07 AM.

  2. #42

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Re: using .getElementsByName

    give me error :

    Specified cast is not valid.

    on line # 6

    if i'm not wrong i cannot refer to form components from the thread's sub , correct ?

  3. #43
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: using .getElementsByName

    Oh yeah I forgot that there's always problems with accessing via threads, I've been meaning to have a look at documentation on that for ages.

    The only (very messy) suggestion I can make to work-around not being able to access it directly is to create another global variable such as "isWbReady" (boolean) and set it to false, then create a timer with interval of 300-500 or so, and add

    Code:
    If WebBrowser1.ReadyState < 4 then
         isWbReady = False
    Else
         isWbReady = True
         Timer1.Stop()
    End If
    Then change your sub slightly to this:

    Code:
    Private Sub Wait()
         While (isWbReady = False)
                Threading.Thread.Sleep(100)
         End While
         '//next procedure
    End Sub
    You might have to turn of the "checkforillegalcrossthreadcalls" property though.

    Sorry, it's really messy.

  4. #44

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Re: using .getElementsByName

    ok i have this :

    Code:
     Sub Wait(ByVal wb)
    
            Do
                Threading.Thread.Sleep(500)
                Label1.Text = "Waiting..."
                Me.Refresh()
    
            Loop While wb.ReadyState < 4 Or Me.wb.IsBusy = True
    End Sub
    How do i make this run in a seperate thread ?

  5. #45

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Re: using .getElementsByName

    also i found out "links" property for htmldocument , can some 1 tell me how do i get element id's or inner text of all the links on a page ?

  6. #46
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: using .getElementsByName

    Quote Originally Posted by sk8er_boi View Post
    also i found out "links" property for htmldocument , can some 1 tell me how do i get element id's or inner text of all the links on a page ?
    What do you mean "links" property? You mean the tagname for links or what? And you need to stop thinking of everything in terms of elementID's as well, elementID is a means to an end...you're looking for the end result, not trying to complicate it by stepping backwards to go forwards.

  7. #47

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Re: using .getElementsByName

    @ J-Deezy : i really appreciate ur help (and patience ! ) , i knw i'n getting confused but i'm a rookie with vb .net & it's kinda my hobby, now i really cnt sleep peace fully until i complete this !!!

    i mean using this :

    http://msdn.microsoft.com/en-us/libr...ent.links.aspx

    using this can i save all the links in a array & then send "click" event to the 1 i need

  8. #48
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: using .getElementsByName

    Sorry I've never used properties before and so I'm not quite sure how to use that

    I thought you'd already figured out how to find your element and everything?

    As for creating a thread for the wait sub, I went through that, in detail a few posts ago.

Page 2 of 2 FirstFirst 12

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