Results 1 to 12 of 12

Thread: Programatically clicking links in WebBrowser control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434

    Programatically clicking links in WebBrowser control

    Hello

    I have an app that logs onto a web page. And manipulates the page. I want it to click on a link. I tried this but it failed:
    Code:
    brwWebBrowser.Document.All.Item("Weather").Click
    I get a "run time error 91 objectvariable not set".
    This code works for clicking on the submit button in the same procedure but not on the links. What am I doing wrong?

    The html code for the link is:
    <a href="Weather.asp">Weather</a><BR>

    Thanks

    David RH
    Last edited by David RH; May 3rd, 2003 at 01:10 AM.

  2. #2
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    give to a link object a name:

    Code:
    <a href="Weather.asp" name="weather">Weather</a><BR>

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    Thanks for the reply Andreys,

    It's not my web sight so I can't make that change.

    What I want to do is have a button that the user clicks and they are taken to the page in question.

    I Have spent way too many hours trying to get this one little convenience function to work. I think I am going to just put it in the docs for the user to navigate there on their own and stop wasting my time on it.

    I wish there was decent documentation out there on a lot of this stuff.


    Thanks again

    David

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Still there is a way to do it.
    Try

    VB Code:
    1. Private Sub Command1_Click()
    2.     For Each el In brwWebBrowser.Document.All
    3.        If el.tagName = "A" Then
    4.             If el.href = "http://WebSiteName/weater.asp" Then
    5.                 el.Click
    6.             End If
    7.        End If
    8.     Next
    9. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    Do I need to declare el as an object variable or variable of some kind? I'm getting an error: "Variable not defined" for el. I'm assuming that it's for element but the full word doesn't work either.

    Thanks

    David

  6. #6
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Dim el

    Leave it as variant.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    Ok I declared el like this:
    Code:
    Dim El As HTMLAnchorElement
    And it works now. But...
    This page has frames and I can't figure out how to point it at the frame with the menu that I'm trying to click on. (I know I should have quit back when I said I was going to) So far I can' only get it to work thru the frameset page (/frame.asp)and then it quits. I tried several ways of working "Frame" into the brwWebBrowser.Document.All part of the statement with no sucess. - object doesn't support this property or method -

    Any Ideas?

    Thanks

    David
    Last edited by David RH; May 4th, 2003 at 09:13 PM.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    Opps looks like we crossed in the mail.

    Should I change it to a variant or leave it as I have it declared now? It seems to be working as is.

    Thanks

    David
    Last edited by David RH; May 4th, 2003 at 09:14 PM.

  9. #9
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    I don't think it's possible with frames.
    The only way that I can think of, is this:
    Code:
    Private Sub Command1_Click()
    Dim el, elInFrame, strLink
    
        For Each el In brwWebBrowser.Document.All
            If el.tagname = "FRAME" Then
                
                strLink = "http://SiteName/" & el.src
                brwWebBrowser.Navigate strLink
                DoEvents
                
                For Each elInFrame In brwWebBrowser.Document.All
                    If elInFrame.tagname = "A" Then
                        If elInFrame.href = "http://SiteName/weather.asp" Then
                            elInFrame.Click
                        End If
                    End If
                Next
            
            End If
        Next
    End Sub

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    Interesting I got it to call a frame up by it's self. but not the one that I was calling. That's about all I can manage.

    But a wierd thing did happen while I was working on it. I had another compleately separate IE (6.0) window open in the background and the page pops up there. It was not connected to my app and it didn't even have the focus. Go figure.

    David

  11. #11
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    While I was looking on my last post, I got one question came on my mind:
    Why do you need click on link programmically, if you already know that is href is?
    Would be easy for you just do
    Code:
    WebBrowser1.Navigate "http://yoursite/weather.asp"

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    Well...

    I have a button in my app that launches the browser control and then logs on to the sight. The user then has to hit 2 more links and then a button back in the app to get the finished product.

    I just wanted the user to be able to have to hit one button and get the finished product.

    The reason that I need to hit the link is that depending on the users department the form that they get back will be different. The form usually handles this in the backround based on what it already knows about the user. This means there are 12 different forms that I have to have links for and then figure out which this user needs.

    I guess I could put a box in the user preferences for them to designate their department and just do a select case on it.

    Also this method calls up just the one frame so the user is done going anywhere else on the sight unless they restart the browser and logon again. ( No more frames with the buttons and hyperlinks and Can't hit back as the page has been expired as soon as you leave it)

    This is a clasic case of trying to so something more efficiently and with less code and spending hours to do what should have taken 5 minutes. At this point I think I keep at this feature because I have so much time invested in it and I don't want it to have been for nothing. Time to cut my loses and get on with life I think.

    Well that's my tale of woe.

    Thanks for your time and the shoulder to cry on.

    David
    Last edited by David RH; May 6th, 2003 at 10:26 AM.

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