We help IT Professionals succeed at work.

recurse through the entire web page to find an element

zazenz asked
Medium Priority
Last Modified: 2010-05-01
How to recurse through the entire web page (dom structure) which contains frames, iframes and look for a particular element (say a button) ?
Watch Question

is it always the same button?

if so, then you can use InStr function


that wouldn't work. in the first place how do i get hold of the source code for the iframe ?

what is your starting point?

are you developing a plugin for ie/ firefox
are you reading a html file on your pc,
do you need to read html files on a server
do you have a webbrowser control in your app?


thanks for responding. its a html page on my PC.


i'll elaborate this a bit, A recursive algorithm that parses the entire dom tree and shows if an element is present or not. any ideas on this would be greatly appreciated.

do you want to compare it to a default page?
(same structure but then with different text or somthing?)

because you can parse it all, but i don't exactly understand what you are trying to do so it is very difficult to answer in the good direction


what I am trying accomplish here is look for a particular element (button) in the web page and click it. This page that I am talking about has many frames and is kind of complex with a huge dom structure. So my Vb program has to parse through each frame and look for if the element exists or not. and if the particular element exists then it has to take an action. I am working on writing the algorithm and any ideas regarding this is a great welcome.

you could do somthing like this:

Dim tmp As String, tmp2 As String, i As Long
tmp = "<your<html> here>"
While tmp <> ""
    i = InStr(tmp, "<")
    If i > 0 Then
        tmp = Right$(tmp, Len(tmp) - i + 1)
        i = InStr(tmp, ">")
        If i = 0 Then MsgBox "Error in html!": Exit Sub
        tmp2 = Left$(tmp, i)
        'process whatever you want
        'the first element is now in tmp2
        tmp = Right$(tmp, Len(tmp) - i)
        tmp = ""
    End If

maybey you can even keep some sort of stack with the elements you encountered

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


thanks a lot, i'll give it a try and shall let you know about it.


           I figured it out. I used some of your ideas. and thanks for all the help.

well, i'm glad you have figured somthing out!

and thanx for the points,
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.