|
-
May 2nd, 2003, 07:50 PM
#1
Thread Starter
Hyperactive Member
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.
-
May 3rd, 2003, 06:09 PM
#2
Frenzied Member
give to a link object a name:
Code:
<a href="Weather.asp" name="weather">Weather</a><BR>
-
May 3rd, 2003, 08:28 PM
#3
Thread Starter
Hyperactive Member
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
-
May 4th, 2003, 01:07 AM
#4
Frenzied Member
Still there is a way to do it.
Try
VB Code:
Private Sub Command1_Click()
For Each el In brwWebBrowser.Document.All
If el.tagName = "A" Then
If el.href = "http://WebSiteName/weater.asp" Then
el.Click
End If
End If
Next
End Sub
-
May 4th, 2003, 02:21 PM
#5
Thread Starter
Hyperactive Member
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
-
May 4th, 2003, 06:56 PM
#6
Frenzied Member
Dim el
Leave it as variant.
-
May 4th, 2003, 07:04 PM
#7
Thread Starter
Hyperactive Member
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.
-
May 4th, 2003, 07:08 PM
#8
Thread Starter
Hyperactive Member
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.
-
May 5th, 2003, 10:53 AM
#9
Frenzied Member
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
-
May 5th, 2003, 11:22 PM
#10
Thread Starter
Hyperactive Member
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
-
May 5th, 2003, 11:48 PM
#11
Frenzied Member
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"
-
May 6th, 2003, 12:43 AM
#12
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|