?
Solved

GetElementByID - using webbrowser when ID is not unique on the page

Posted on 2008-11-11
4
Medium Priority
?
615 Views
Last Modified: 2013-12-17
I'm trying to retrieve an element which is a dropdown (select/options) element).  Unfortunately the programmer used the same name for an image on the page as for the select object.  When I use getElementByID - I get the image - and thus can't get to the 2nd object with that name. Is there any way I can iterate through all the elements in the document to find both of them -  or to specify the type of control I want it to search for?  
0
Comment
Question by:CreditSoupTech
  • 2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Mark Steggles
ID: 22932272
An id should be unique in the document. Rather than trying to find another way to get to the select you should fix the cause of this issue. You should change either the image or the select to a unique id.
0
 
LVL 4

Accepted Solution

by:
CreditSoupTech earned 0 total points
ID: 22932681
  When you're screen scraping you don't have the luxury of making corrections on the source pages.
    Thanks anyway.  I think I found how to loop through the elements and that might allow me to get the right one.


 HtmlDocument doc = webBrowser1.Document;
                elems = doc.All.GetElementsByName("");

                if (elems != null && elems.Count > 0)
                    for (int i = 0; i < elems.Count; i++)
                    {

                        {
                            elem = elems[i];
                            if (elem.TagName.Equals("FORM"))
                            {
                                elem.InvokeMember("Submit");
                                break;
                            }
                        }
                    }

0
 
LVL 30

Expert Comment

by:Mark Steggles
ID: 22932806
O sorry. I didnt know the situation.

i think you could also do it like this:

var selects = document.getElementsByTagName('select');
for(i=0;i<selects;i++) {
  if(selects[i].id == 'yourID') {
   do your stuff
}
}
0
 
LVL 4

Author Comment

by:CreditSoupTech
ID: 22932833
Thanks.  That might work. I got the other solution working though so I quit playing with it.  
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

621 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