[C#] I need some help

nothingmore

Junior Member
Joined
May 1, 2011
Messages
190
Reaction score
219
This is my first project and after a couple days I finally am getting some progress.

Here is my current code right now which I made just to make sure it works and it did. How do I go about making a loop that will grab the ID (which is an assigned user number) and click each time because I would need this to loop 1000+ times.

Code:
private void button1_Click_1(object sender, EventArgs e)
        {
            HtmlDocument doc = webBrowser1.Document;
            HtmlElement f1 = doc.GetElementById("user3800");
            HtmlElement f2 = doc.GetElementById("user6341");
            HtmlElement f3 = doc.GetElementById("user5822");
            HtmlElement f4 = doc.GetElementById("user1645");
            HtmlElement f5 = doc.GetElementById("user4909");
            f1.InvokeMember("click");
            f2.InvokeMember("click");
            f3.InvokeMember("click");
            f4.InvokeMember("click");
            f5.InvokeMember("click");
        }
 
parse user ids into array/list, and then in loop call GetElementById(arrayElement) InvokeMember("click")
 
You mean like

Code:
string[] ids = new string[5] {"user3800", "user6341", "user5822", "user1645", "user4909"};

HtmlDocument doc = webBrowser1.Document;

for (int i = 0; i < ids.Length; i++)
    doc.GetElementById(ids[i]).InvokeMember("click");

I haven't tested the code.. but it should do the job
 
Yes that works.

My only problem is I don't want to have to manually enter in the ID. So I'm trying to figure out how to grab the user id's with something like id.contains("user"). Does that make sense? Thanks for the help.
 
Last edited:
Then it'd be something like this

Code:
HtmlDocument doc = webBrowser1.Document;
HtmlElementCollection links = doc.GetElementsByTagName("a");

foreach (HtmlElement link in links)
    if (link.GetAttribute("id").Contains("user"))
        link.InvokeMember("click");
 
Thank you so much!!! +rep and thanks. I appreciate it so much.
 
Back
Top