there are buttons on the site that the browser constantly presses, every 5 seconds the page loads and new buttons appear with the same name, the question is how to make the timer invoke the button every 5 seconds to click a button? Here's how:
private void button1_Click(object sender, EventArgs e) { System.Timers.Timer myTimer = new System.Timers.Timer(4000); myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed); myTimer.Start(); } void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { HtmlElementCollection elmCol = webBrowser1.Document.GetElementsByTagName("span"); //исключение тут foreach (HtmlElement elmBtn in elmCol) { if (elmBtn.GetAttribute("className") == "button-text follow-text") { elmBtn.Focus(); elmBtn.InvokeMember("Click"); } } } but throws an exception: System.InvalidCastException . Without a timer, the buttons are pressed perfectly, the click code is correct