0

I'm currently working on a bot that would automatically, given the correct parameters, create an account on my favourite websites. I chose for this example Twitter. The problem is, when I debug this, it loads the form, fills in the correct fields, but the click button is not working and I can't figure out why.

I've watched on the event listeners in the Chrome debug tool, and it says that there's a click function, but I can't call it!

Thanks in advance

The URL I'm working on is : www.twitter.com/signup/

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HtmlDocument doc = webBrowser1.Document;
        HtmlElement fullname = doc.GetElementById("full-name");
        HtmlElement email = doc.GetElementById("email");
        HtmlElement password = doc.GetElementById("password");
        HtmlElement username = doc.GetElementById("username");
        fullname.SetAttribute("value", "JustARandomTest");
        email.SetAttribute("value", "randomtest@test.com");
        password.SetAttribute("value", "randomtest");
        username.SetAttribute("value", "randomtest10");
        HtmlElement button = doc.GetElementsByTagName("input")["submit_button"];
        button.InvokeMember("click");




    }
}

}

toadflakz
  • 7,764
  • 1
  • 27
  • 40
devconnected
  • 123
  • 9
  • 3
    *I know there're posts already related to this kind of problem, but I wanted you to assist me on this specific problem!*... meaning *I know there're posts already related to this kind of problem, but I can't be bothered to read them all and extrapolate the solutions to my specific problem!* – Sheridan Jul 24 '14 at 07:45
  • Hey... that's just my interpretation of the words that *you* used. Judging by the up vote on the comment, it seems like I'm not the only one here that thinks that way. – Sheridan Jul 24 '14 at 07:57
  • 1
    How is this a WPF question? WPF has nothing to do with HTML? – toadflakz Jul 24 '14 at 08:01
  • If only we used that time to solve the problem.. I'm not asking for answers, I'm asking for where I'm missing the point! Anyway good day Sir – devconnected Jul 24 '14 at 08:01
  • U need to use the `WebRequest` class (http://msdn.microsoft.com/en-us/library/456dfw4f%28v=vs.110%29.aspx) – DarkBee Jul 24 '14 at 08:41
  • Hey there! Thanks for the comment! I already wrote a class with WebRequest, doing a GET and a POST request to the server but it couldn't work properly, since Twitter is using some kind of bizarre encoding in its cookies and it is also going though Analytics which might be a problem. That's part of the reason I switched to a HtmlDocument class. – devconnected Jul 24 '14 at 08:44
  • Use a cookie jar to put those cookies in (http://stackoverflow.com/questions/571964/automatic-cookie-handling-c-net-httpwebrequesthttpwebresponse) – DarkBee Jul 24 '14 at 09:05
  • I don't want to do it via HttpWebRequest, it's just too annoying while emulating a WebBrowser is so much easier! I just want to know the parameter I have to set in the InvokeMember to click :) – devconnected Jul 24 '14 at 09:17
  • PerformClick is a method used by a Button from the Forms class isn't it? I'm using an HtmlElement.. – devconnected Jul 24 '14 at 09:23
  • http://stackoverflow.com/questions/5309337/how-to-click-a-link-element-programmatially-with-htmlelement – DarkBee Jul 24 '14 at 09:32
  • I doubt you actually read my code, sorry to say that.. You're linking me to an answer that is globally my code. – devconnected Jul 24 '14 at 09:47
  • I doubt u read that answer. `GetElementsByTagName` returns a `HtmlElementCollection`, not a single element. Just assuming the index `submit_button` would contain your button is wrong. – DarkBee Jul 24 '14 at 10:30
  • Dude... HtmlElement button = doc.GetElementsByTagName("input")["submit_button"] returns an HtmlElement, have you seen the ["submit_button"]? I'm looking into the Collection to find a specific Element.. – devconnected Jul 24 '14 at 11:34
  • Are u sure the id of the input is `submit_button` ? I just set this up in a project and if the input id is `submit_button`the code works.. – DarkBee Jul 24 '14 at 13:35
  • When I look at the properties of the HtmlElement I'm getting, it seems to be the right object. Anyway, I know use the Watin library which is very easier to do it. Let me thank you for your time! – devconnected Jul 24 '14 at 15:16

0 Answers0