Results 1 to 3 of 3

Thread: Problem Programatically clicking links in WebBrowser control

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Problem Programatically clicking links in WebBrowser control

    Hi all i have html page loaded in to my webbrowser controle that looks like this:
    <a href="http://www.somesite.com/recordds.wmt?page=31" title="Go to Next Page" onfocus="if(this.blur)this.blur();"
    > &nbsp;next &raquo;</a>

    I used the following code to click on it but it doesn't work . could you guys tell me what i am doing wrong ? Thanks

    Code:
    Private Sub Command8_Click()
    For Each ele In WebBrowser1.Document.getelementsbytagname("a")
    If ele.innertext = "&nbsp;next &raquo;" Then ele.Click
    Next
    End Sub
    or

    Code:
    Private Sub Command8_Click()
    For Each ele In WebBrowser1.Document.getelementsbytagname("a")
    If ele.innertext = "next" Then ele.Click
    Next
    End Sub

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

    Re: Problem Programatically clicking links in WebBrowser control

    try
    if instr(ele.innertext, "next") > 0 then ele.click
    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
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem Programatically clicking links in WebBrowser control

    Quote Originally Posted by westconn1 View Post
    try
    if instr(ele.innertext, "next") > 0 then ele.click
    Many thanks it worked well. Is there away that wait untill the next button load the page in webbrowser then do other things ? I tried this but it never loades the new next page only it loads whatever the page was in text1.text at start over and over . only at the end the next page get clicked once but even then text1 doesn't show the last new url!

    could you help me fix this problem.Thanks


    Code:
    Private Sub Command9_Click()
    For i = 0 To 4
    
        TxtHTML = ""
    RichTextBox1 = ""
    WebBrowser1.Navigate Text1.Text
    TxtHTML = Inet1.OpenURL(Text1.Text)
    Label2.Caption = "Current Item:" & i
    
       Do Until WebBrowser1.ReadyState = 4
        DoEvents
        Loop
     
    Text1.Text = ""
    
    Command2_Click ' chap html
    Command3_Click 'get items
    
    For Each ele In WebBrowser1.Document.getelementsbytagname("a")
    'If ele.innertext = "Go to Next Page" Then ele.Click
    If InStr(ele.innertext, "next") > 0 Then ele.Click
    Next
    
    
    'wait for webbrowser to load then go next
    
       Do Until WebBrowser1.ReadyState = 4
        DoEvents
        Loop
        
    Text1.Text = WebBrowser1.LocationURL
    
    Next i
    MsgBox "Complete"
    
    End Sub
    Last edited by tony007; May 6th, 2010 at 10:46 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