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

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?  
LVL 4
CreditSoupTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark StegglesWeb DeveloperCommented:
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
CreditSoupTechAuthor Commented:
  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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark StegglesWeb DeveloperCommented:
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
CreditSoupTechAuthor Commented:
Thanks.  That might work. I got the other solution working though so I quit playing with it.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

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.