Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A program to automate the process of checking a set of UserIds passing as a input to a webform in a url and get the status using webbrowser . for Single Ids its working , but to automate for N number of ids, loop is not working but taking the last id and returns the output .

 private void button2_Click(object sender, EventArgs e)
        {
            string url = "https://www.verify.xhtml";
            WebBrowser b = new WebBrowser();
            b.ScriptErrorsSuppressed = true;
            b.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted);
            b.Navigate(url);
        }


<pre>private void b_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

            for (int i = 0; i <= 4; i++)
            {
                WebBrowser b = sender as WebBrowser;
                b.Document.GetElementById("idnumber").InnerText = idarray[i];
                //string listobj = b.Document.GetElementsByTagName("select")[0].GetElementsByTagName("option")[1].SetAttribute("selected", "selected");
                // string response = b.DocumentText;

                b.Document.GetElementById("frmType1").SetAttribute("value", "24Q");

                HtmlElement btnlink = b.Document.GetElementById("clickGo1");
                btnlink.InvokeMember("Click");
                b.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted);
                b.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(b_result);

            }
        }

What I have tried:

I am getting the result from the site for the last ID ..how to perform the loop start from the first ID .. Please suggest me some changes in this code to get the code work as expected . thanks
Posted
Updated 15-Jul-19 20:04pm
v2

1 solution

Well yes, you will.
You are running a loop, but all you ever do is assign values to variables - at no point to do you include the existing value, you just overwrite what was there. So what you end up with is always the last value.

It's a bit like trying to write a loop to add up numbers:
C#
int result = 0;
for (int current = 1; current <= numberOfValues; current++)
   {
   result = current;
   }
Console.Writeline(result);
will always give you the same result - the number of values to "add up". If you include the existing values, it will work:
C#
int result = 0;
for (int current = 1; current <= numberOfValues; current++)
   {
   result += current;
   }
Console.Writeline(result);
You need to do something similar in your code.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900