1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[C#] I need some help

Discussion in 'C, C++, C#' started by nothingmore, Jun 13, 2012.

  1. nothingmore

    nothingmore Junior Member

    Joined:
    May 1, 2011
    Messages:
    190
    Likes Received:
    219
    Location:
    The Lounge
    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");
            }
    
     
  2. skrode

    skrode Junior Member

    Joined:
    Nov 13, 2011
    Messages:
    103
    Likes Received:
    16
    parse user ids into array/list, and then in loop call GetElementById(arrayElement) InvokeMember("click")
     
  3. vis3r

    vis3r Registered Member

    Joined:
    Jul 25, 2008
    Messages:
    63
    Likes Received:
    31
    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
     
    • Thanks Thanks x 1
  4. nothingmore

    nothingmore Junior Member

    Joined:
    May 1, 2011
    Messages:
    190
    Likes Received:
    219
    Location:
    The Lounge
    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: Jun 13, 2012
  5. vis3r

    vis3r Registered Member

    Joined:
    Jul 25, 2008
    Messages:
    63
    Likes Received:
    31
    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");
    
     
    • Thanks Thanks x 2
  6. nothingmore

    nothingmore Junior Member

    Joined:
    May 1, 2011
    Messages:
    190
    Likes Received:
    219
    Location:
    The Lounge
    Thank you so much!!! +rep and thanks. I appreciate it so much.
     
  7. business.311921

    business.311921 Newbie

    Joined:
    Jul 12, 2012
    Messages:
    16
    Likes Received:
    1
    i hope.you got required help.if you still need any help let me know :).