accessing individual links using mshtml.HTMLDocument

P9142

Member
Joined
Dec 13, 2005
Messages
11
Programming Experience
3-5
Sorry for the newbie question, but this is driving me nuts. I am trying to access each link individually, but am having trouble. When I try this:

htmldoc = DirectCast(Explorer.Document, mshtml.HTMLDocument)
Debug.WriteLine(htmldoc.links(2).innerText) 'writing innerText of second link

I keep getting this message: Interface 'mshtml.IHTMLElementCollection' cannot be indexed because it has no default property.

Any ideas?
 
VB.NET:
htmldoc.[B]links.item[/B](2).innerText
Why do you use mshtml in .Net 2.0?
 
Sorry, I am an uber newbie. Should I be doing something else? I just realized that I didn't input my code entirely correctly. It should look like this:

Dim htmldoc As mshtml.HTMLDocument
htmldoc = DirectCast(Explorer.Document, mshtml.HTMLDocument)
Debug.WriteLine(htmldoc.links(2).innerText)
 
It depends, but there exist framework inbuilt Webbrowser control and HtmlDocument class.
 
Well, what is there to tell? You should use the .Net framework if you can instead of a 9 years old COM product, usually easier to work with the new.
 
I am using Visual Studio .NET 2003 which is .NET 1.1

Can I still use the same functionality you described above, or do I need .NET 2.0?
 
No, it's new in .Net 2.0, but it also depends on the situation when it can be used. Btw, did you know you are saying this:
P9142
user_online.gif

VB.NET Forum Newbie
Primary Platform: .NET 2.0 (VS 2005)
 
Not more than you are stuck with .Net 1.1, but you haven't told what you are doing exactly either. So even if you go .Net 2.0 you might still have to use mshtml.
 
OK, I feel like a huge noob, which I am. Basically what I am trying to do is create a program which will go though each link in a webpage individually just like you would if you were pressing the tab key each time. I want the program to automate this process waiting half a second before moving to the next link, and highlight each link when it is onFocus and unhighlight for each onBlur. This seems like it should be simple enough, but I am such a noob that the programming seems like an insurmountable task right now.

I can simulate the functionality like this:


ForEach link As mshtml.HTMLAnchorElement In htmldoc.links
link.focus()
link.style.backgroundColor() = "#AAFFFF"
System.Threading.Thread.Sleep(500)
link.blur()
link.style.backgroundColor() = "#FFFFFF"
Next

However, I need to be able to control the direction of the scan. For example, I want to be able to scan forwards and backwards. I also need to be able to start the scan at a pre-determined spot, so I need to access each link individually. There seems to be an array of links, but when I try to access them individually I keep getting this error message:

Interface 'mshtml.IHTMLElementCollection' cannot be indexed because it has no default property.
 
Last edited:
I told you in first reply, you have to use the ITEM property of the links collection to access.
 
Back
Top