We help IT Professionals succeed at work.

# recurse through the entire web page to find an element

on
Medium Priority
158 Views
How to recurse through the entire web page (dom structure) which contains frames, iframes and look for a particular element (say a button) ?
Comment
Watch Question

## View Solution Only

Commented:

is it always the same button?

if so, then you can use InStr function

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

Commented:

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

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

Commented:
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.

Commented:

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

Commented:
Mark_FreeSoftware,
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.
Commented:

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)
Else
tmp = ""
End If
Wend

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.

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

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

Commented:

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

and thanx for the points,
mark
##### Thanks for using Experts Exchange.

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