473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Finding all <A> elements on a page

There is a web page that has a bunch of links on it (i.e. "<A
HREF=..."). I am trying to automate clicking on one in a WebBrowser
control. However when I execute the following code:

Dim oCollection As HtmlElementCollection
oCollection = WebBrowser1.Document.GetElementsByTagName("A")

oCollection.Count is ZERO. I am assuming that I'm not using the
correct Tag Name. I also tried "a" and "link" but they also return no
elements.

What is the correct Tag Name to use?

Is there a list of the possible tag names somewhere?
Nov 13 '08 #1
5 8671
On Nov 13, 7:45*am, BobRoyAce <b...@omegasoftwareinc.comwrote:
There is a web page that has a bunch of links on it (i.e. "<A
HREF=..."). I am trying to automate clicking on one in a WebBrowser
control. However when I execute the following code:

* * Dim oCollection As HtmlElementCollection
* * oCollection = WebBrowser1.Document.GetElementsByTagName("A")

oCollection.Count is ZERO. I am assuming that I'm not using the
correct Tag Name. I also tried "a" and "link" but they also return no
elements.

What is the correct Tag Name to use?

Is there a list of the possible tag names somewhere?
Hi Bob,
Using "A" (anchor) as tag to get links should be correct, as i tried
to navigate "www.google.com", "oCollection.Count" returned 29 items.
However you can try "Webbrowser1.Document.Links.Count" to get same
result.

And if you want to get all the links using
"WebBrowser1.Document.Links", just loop through it using GetAttribute
function by specifying "href" as follows:

For Each item As HtmlElement In WebBrowser1.Document.Links
' Do whatever you want with found links
item.GetAttribute("href")
Next

Hope this help,

Onur Güzel
Nov 13 '08 #2
Using "A" (anchor) as tag to get links should be correct, as i tried
to navigate "www.google.com", "oCollection.Count" returned 29 items.
However you can try "Webbrowser1.Document.Links.Count" to get same
result.
Yea, thought "A" for tag name should be fine. I think it's an issue
with the browser not finished downloading the document.
I am using the following code, running it before I check for the "A"
tags. Should it work?

While WebBrowser1.ReadyState <WebBrowserReadyState.Complete
Application.DoEvents()
End While
And if you want to get all the links using
"WebBrowser1.Document.Links", just loop through it using GetAttribute
function by specifying "href" as follows:

For Each item As HtmlElement In WebBrowser1.Document.Links
' Do whatever you want with found links
item.GetAttribute("href")
Next
Thanks...
Nov 21 '08 #3
On Nov 21, 4:42*pm, BobRoyAce <b...@omegasoftwareinc.comwrote:
Using "A" (anchor) as tag to get links should be correct, as i tried
to navigate "www.google.com", "oCollection.Count" returned 29 items.
However you can try "Webbrowser1.Document.Links.Count" to get same
result.

Yea, thought "A" for tag name should be fine. I think it's an issue
with the browser not finished downloading the document.
I am using the following code, running it before I check for the "A"
tags. Should it work?

* * While WebBrowser1.ReadyState <WebBrowserReadyState.Complete
* * * Application.DoEvents()
* * End While
And if you want to get all the links using
"WebBrowser1.Document.Links", just loop through it using GetAttribute
function by specifying "href" as follows:
*For Each item As HtmlElement In WebBrowser1.Document.Links
' Do whatever you want with found links
*item.GetAttribute("href")
Next

Thanks...
You can use the code in my previous post in Webbrowser's
DocumentCompleted event handler if your wish is to get all the links
when webbrowser finishes loading. When loading finishes, now it should
count all the elements that refer to links.

Thanks,

Onur Güzel
Nov 21 '08 #4
Unless you know of a better way to do things, I have found that using
the DocumentCompleted method is a pain in the neck because there are a
bunch of different documents/pages that ultimately get loaded and, so,
the application needs to keep track of which one was just
loaded...this because the single DocumentCompleted event is shared by
all documents/pages. Why is it that the code that posted, waiting for
ReadyState to equal Complete, doesn't work? Perhaps the ReadyState is
set before the document/page has been downloaded?
Nov 21 '08 #5
On Nov 21, 8:10*pm, BobRoyAce <b...@omegasoftwareinc.comwrote:
Unless you know of a better way to do things, I have found that using
the DocumentCompleted method is a pain in the neck because there are a
bunch of different documents/pages that ultimately get loaded and, so,
the application needs to keep track of which one was just
loaded...this because the single DocumentCompleted event is shared by
all documents/pages. Why is it that the code that posted, waiting for
ReadyState to equal Complete, doesn't work? Perhaps the ReadyState is
set before the document/page has been downloaded?
Well, then you'd better check out this blog entry, it demonstrates how
to add an event that is raised when ReadyState indicates the browser
control is completed loading.
It's in C#, but you can convert to VB.NET of course using with an
online converter or by yourself.

http://afjohansson.spaces.live.com/blog/cns!3CA68ED86F5A5970!376.entry

Hope this helps,

Onur Güzel
Nov 21 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
6
by: Joe | last post by:
I have a: vector<string> which contains a few dozen elements. I want to find the index of the element containing a certain string. for example: vector<string> strings;...
3
by: | last post by:
I have been researching articles on google on how to create a simple RSS feed that sucks <title><blurb><link><date> out of a sql server 2000 database via an aspx page. I know it has to be pushed...
3
by: Dave Booker | last post by:
Am I missing something here? It looks like the generic Queue<T> implements Enumerable<T> and ICollection but not ICollection<T>. (I want to use it in an interface that wants an ICollection<T>.) ...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.