Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void webBrowser1_DocumentCompleted_Vote()
- {
- //Click the vote button
- HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("input");
- foreach (HtmlElement el in elc)
- {
- if (el.GetAttribute("type").Equals("submit") && el.GetAttribute("value").Equals("Vote now"))
- {
- el.InvokeMember("Click");
- }
- }
- //Wait to make sure vote has gone through. This loop will stop after 10 unsuccessful checks
- bool voted = false;
- for (int i = 0; i < 10; i++)
- {
- //Sleep for 1 second, then check
- Thread.Sleep(1000);
- //The innerHTML of your webBrowser control will only have the 'day today has-voted' text
- //once the vote has gone through. (or if you have already voted today I suppose. You may
- //want to check for that somewhere I guess. The button click might not work if you have
- //already voted, sooo yeah. Not sure.)
- //I removed spaces because there was weird formatting with multiple spaces on this section
- //of the page, so it is best to just remove them before the check to avoid issues
- if (webBrowser1.Document.Body.InnerHtml.Replace(" ", "").Contains("daytodayhas-voted"))
- {
- //The vote has gone through. Set voted to true and break out of the for loop.
- voted = true;
- break;
- }
- }
- //If voted is not true that means the loop ran 10 times without success.
- if (!voted)
- {
- MessageBox.Show("Error: Voting failed");
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment