[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Close Button, getElementById, overlay

Posted on 2012-09-10
9
Medium Priority
?
799 Views
Last Modified: 2012-09-18
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?
0
Comment
Question by:HLRosenberger
9 Comments
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38384059
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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 38384135
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
 
LVL 20

Expert Comment

by:informaniac
ID: 38384182
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 38384469
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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 38391922
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
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38394178
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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 38394386
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
 
LVL 1

Accepted Solution

by:
HLRosenberger earned 0 total points
ID: 38395302
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
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 38408709
This is the only solution that worked for me.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question