C#: How to break out of this loop?

Status
Not open for further replies.

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
Basically I am trying to click enter on this site for a program I am working on. I asked on another forum and they supplied me with a foreach loop. The thing is the foreach loop keeps looping xD. I even added a break command to it but it still constantly clicks enter.

Can you help me stop it?

p.s: Its located in the Document_Completed event.

Code:
if (webBrowser1.Url.AbsoluteUri.Contains("http://www.mailinator.com/"))             {                  webBrowser1.Document.GetElementById("email").SetAttribute("value", txtMailName.Text);                                  HtmlElementCollection inputs = webBrowser1.Document.GetElementsByTagName("input");                  foreach (HtmlElement input in inputs)                 {                     if (input.GetAttribute("name") == "email")                         input.Focus();                     SendKeys.Send("{ENTER}");                     break;                 }             }
http://www.blackhatworld.com/blackhat-seo/editpost.php?do=editpost&p=3170573
 

Darkness

Veteran
veteran
old school
senior
Life Saver
coldschool
member
Joined
Jul 17, 2009
Posts
3,361
Reaction score
2,442
Points
180
Location
Toronto, Canada
It would help if the syntax was correctly spaced :p

Edit: Try this out:
Code:
 if (webBrowser1.Url.AbsoluteUri.Contains("http://www.mailinator.com/"))
            { 
                webBrowser1.Document.GetElementById("email").SetAttribute("value", txtMailName.Text); 
                foreach (HtmlElement name in webBrowser1.Document.All) 
                { 
                    if (name.GetAttribute("name") == "email") 
                    name.Focus(); 
                    SendKeys.Send("{ENTER}");
                    break; 
                } 
            }
 

krazedkat

Old School
old school
member
Joined
Dec 20, 2009
Posts
492
Reaction score
19
Points
108
Age
28
I don't see why a for each loop would be infinite, seeing as it should terminate after all elements have been gone over.
 

Darkness

Veteran
veteran
old school
senior
Life Saver
coldschool
member
Joined
Jul 17, 2009
Posts
3,361
Reaction score
2,442
Points
180
Location
Toronto, Canada
I don't see why a for each loop would be infinite, seeing as it should terminate after all elements have been gone over.

This isn't a problem in the for loop. This is a unique problem concerning the elements themselves. There's prolly a hiccup in the HTML where something is a duplicate, etc.
 

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
Can you help breaking out of the loop. The site is mailinator
 

TheSyndicate

0110100001101001
veteran
senior
member
Joined
May 22, 2011
Posts
2,287
Reaction score
1,345
Points
151
Age
29
Location
Texas
What exactly are you trying to do? Locate the email element, set the focus and press the ENTER key?
 

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
Nevermind guys. I managed to code a workaround to the code. Thanks for your help
 

Patel

Veteran
veteran
old school
senior
member
Joined
Aug 12, 2010
Posts
1,593
Reaction score
489
Points
133
Location
Inside Tang
Website
itspatel.com
in vb.net its Exit Do or Exit For
 
Status
Not open for further replies.