Jump to content

login form using web browser in visual studio (C#)

i  want to login to twitter. this is what i got:

private void Login_Click(object sender, EventArgs e)// when button is clicked
        {
            HtmlDocument doc = webBrowser1.Document;
            HtmlElement username = doc.GetElementById("signin-email");// email field
            HtmlElement password = doc.GetElementById("signin-password");//password field
            username.SetAttribute("value", "email");
            password.SetAttribute("value", "password");

            // this should presss the login button. twitter has no id for login button
            HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("input");
            foreach (HtmlElement el in elc)
            {
                if (el.GetAttribute("type").Equals("submit"))
                {
                    el.InvokeMember("Click");
                }
            
            // Thread.Sleep(1000*3);
            //webBrowser1.Navigate("https://twitter.com/Aivarasatk/following");
        }

this always gets me to login page because my initials where "wrong". Don't really get where the problem is. And also if i use

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

with the same code, i believe this function loads whenever page is loaded, not once, which i need.
Any suggestions?

 

EDIT: if i use the same code for facebook, it works.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to post
Share on other sites

I could be wrong, since I haven't done website stuff for a while, but shouldn't it be

session[username_or_email]

and

session[password]

 

For the GetElementById?  And using the URL twitter.com/login (I ran things with noscript, so it blocked javascript stuff)

3735928559 - Beware of the dead beef

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×