Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:19:18+00:00 2026-06-05T17:19:18+00:00

Right now when I run this it keeps clicking on the same button every

  • 0

Right now when I run this it keeps clicking on the same button every 2 seconds. I’m trying to figure out how I can go on to the next ID rather than it keep doing the first one it finds then breaking. Here is my code:

private void button2_Click(object sender, EventArgs e)
{
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    HtmlDocument doc = webBrowser1.Document;
    HtmlElementCollection links = doc.GetElementsByTagName("a");

    foreach (HtmlElement link in links)
    {
        if (link.GetAttribute("id").Contains("user"))
        {
            link.InvokeMember("click");
            break;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:19:19+00:00Added an answer on June 5, 2026 at 5:19 pm

    Change your code to this…

    //HtmlElementCollection links = null;
    List<HtmlElement> links = null;
    
    private void button2_Click(object sender, EventArgs e)
    {
        // This way you only get the links once.
        //links = webBrowser1.Document.GetElementsByTagName("a");
        links = new List<HtmlElement>(
            webBrowser1.Document.GetElementsByTagName("a")
            .OfType<HtmlElement>());
    
        timer1.Start();
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        HtmlElement linkToClick = null;
    
        foreach (HtmlElement link in links)
        {
            if (link.GetAttribute("id").Contains("user"))
            {
                linkToClick = link;
                break;
            }
        }
    
        // did I find a link?
        if (linkToClick != null)
        {
            // Remove it from the list so you don't click it again.
            links.Remove(linkToClick);
    
            link.InvokeMember("click");
        }
        else
        {
            // Stop the timer since there are no more items.
            timer1.Stop();
        }
    }
    

    By the way, I don’t know if HtmlElementCollection has a “Remove” method… if it doesn’t, simply use a generic List<> or an ArrayList, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to figure out right now all my core data is managed on
im really desperate right now, ive tried everything. Everytime i run my app this
Right now I can run a PHP script from my Mac terminal like echoing
I'm trying to work with netbeans right now and I've run into a bit
Right now I have this SQL query which is valid but always times out:
Right now whenever I run application It creates a file (file name specified in
Right now, if I want to run mysql, I have to do /Applications/MAMP/Library/bin/mysql -u
We have a script right now which our Windows users run on a Linux
Right now I have double numba = 5212.6312 String.Format({0:C}, Convert.ToInt32(numba) ) This will give
I think I'm doing this inefficiently right now and wanted a suggestion of how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.