Close Button, getElementById, overlay

I have a screen scraper app.   I'm scraping a page that has an overlay - it's that object that makes it look a modal popup, but actually is not.  Now, there are elements within the overlay that I extract data from.  These elements all have ID values.  Now, the overlay has a "Close" button.  I want to click the close button.   The button does not have an ID, so I'm attempting to find it my looping through all the DOM elements and picking off the buttons, by class name, and then examining the text on the button.   However, my loop through all the DOM elements never finds this button that is located within the overlay.   There are other buttons on the page that are not within the overlay, and I do find these within the loop.

Any thoughts on why I cannot find the button within the overlay?
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
HLRosenbergerAuthor Commented:
Maybe this is a MS bug.   Makes no sense why looping through ALL the DOM elements and picking off those with a type of button does not find the Close button

This is what I came up with to find the Close button.  The Close button sits within a pane which does have an ID.   So I use getElementByID to find the pane, and then loop through the children of the pane looking for an element with a value of "Close".
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

I think you can try with jQuery CSS selector!

<input type="button" id="btn" value="Click" /> 

    <script type="text/javascript">
        $(document).ready(function () {
           var btnText = $('#btn').attr('value');
           alert(btnText);
        });
    </script>

Open in new window


Hope it helps u...
0
 
HLRosenbergerAuthor Commented:
To use JQuery, don't I need to own the page?  The JQuery, like Javascript, runs in the page on the client?

I have a .NET console app that extracting data out of the DOM of someone elses page.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Obadiah ChristopherCommented:
Did u try and find the button when the overlay is not opened?

What method are you using to loop through the buttons?

Is it possible that you are not able to find the button since it is inside another div and not the outermost div?
0
 
Daniel Van Der WerkenIndependent ConsultantCommented:
First, you need to make sure the button exists on the page you're scraping like informaniac suggests.

Are you recursively looping through the elements? You need to make sure you find any elements within elements within elements. Share how you're doing the loop. We might be able to help with a recursive mechanism for getting them all. Something like:

       
 public static Control _prvGetFirstControlTypeFromControlCollection( Type param_Control_Type, Control param_Control )
        {
            Control foundControl = null;
            ControlCollection ccc = param_Control.Controls;
            foreach ( Control c in ccc )
            {
                if ( c.GetType() == param_Control_Type )
                {
                    foundControl = c;
                    break;
                }
                else
                {
                    if ( c.Controls.Count > 0 )
                    {
                        foundControl = _prvGetFirstControlTypeFromControlCollection( param_Control_Type, c );
                    }
                }
            }
            return foundControl;
        }

Open in new window


...but this method that I wrote only gets the first instance of a control of the type specified. Plus, it is used by an ASP .NET page that is generating a web page, not a screen scraper. I added it to show you how you might go about implementing your own though.
0
 
HLRosenbergerAuthor Commented:
informaniac

It is inside another div. The overlay is a div.   So, how then do I find it?  I'm doing this to find the button:

 Public Function FindCloseButton(ByVal doc As Object) As HTMLButtonElement

        Dim btn As HTMLButtonElement

        FindCloseButton = Nothing
        For i As Integer = 0 To doc.all.Length - 1

            ' Find Input Element
            If TypeName(doc.all(i)) = "HTMLButtonElementClass" Then

                btn = doc.all(i)
                If btn.innerText = "Close" Then
                    FindCloseButton = btn
                    Exit For
                End If

            End If
        Next i

    End Function
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

Did you tried the solution which i have provided?

Moreover, are you looking for solution in (Server Side)Code behind or Client Side?
0
 
HLRosenbergerAuthor Commented:
Server side.  There is no "client side" in effect, as this is a console app that is a screen scraper.  I' using the SHDocVw.InternetExplorer object.
0
 
HLRosenbergerAuthor Commented:
This is the only solution that worked for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.