+ Reply to Thread
Results 1 to 2 of 2

Thread: Fill forms in web automatically

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    11

    Fill forms in web automatically

    I wanted to create a tool that fill in web forms automatically.
    For example i would like to fill in the sign up form with details i'd provide to application.

    How can i do that ?
    Last edited by juniour; 11-11-2012 at 10:42 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    28
    Requirements ?
    - Web Browser control
    - Firefox browser with FireBug plugin

    Steps :

    1) Install firefox and install firebug the plugin
    2) Restart firefox
    3) go Yahoo Registering page
    3) Hit the firebug button from the top right
    4) The firebug big toolbox should appear at the button taking half of the screen
    5) click on the second icon on the left first row "click an element in the page to inspect"
    6) click on a textbox corresponding to Name
    7) a value should appear down there
    Code:
    <input id="firstname" type="text" aria-required="true" autocomplete="off" maxlength="32" size="32" value="" name="firstname" title="First Name" tabindex="1" class="fieldValInit">
    8) So we got an Input tag correct ?
    9) Now try to click on dropdown box
    10 ) a value should appear like :
    Code:
    <select id="gender" class="" aria-required="true" name="gender" title="Gender" tabindex="3">
    <option selected="" value="">- Select One -</option>
    <option value="m" title="Male">Male</option>
    <option value="f" title="Female">Female</option>
    </select>
    11) that`s a select tag correct ?

    Finally : all we need is to fill the Value property

    OKay now lets head to the C# code

    Steps :

    1) create a web control with web address : https://edit.yahoo.com/registration?...us&.lang=en-US
    2) add these 2 void methods , one for Select tag and the other for Input tag
    Code:
            // Set value for the attribute that has the name (attName)
            private void Set_Text_TAG_INPUT(string attribute, string attname, string value)
            {
                // Get a collection of all the tags with name "input";
                HtmlElementCollection htmle = webBrowser1.Document.GetElementsByTagName("input");
    
                foreach (HtmlElement current in htmle)
                {
                    if (current.GetAttribute(attribute).Equals(attname))
                    {
                        current.SetAttribute("value", value);
                    }
                }
            }
            private void Set_Text_TAG_SELECT(string attribute, string attname, string value)
            {
                // Get a collection of all the tags with name "input";
                HtmlElementCollection htmle = webBrowser1.Document.GetElementsByTagName("select");
    
                foreach (HtmlElement current in htmle)
                {
                    if (current.GetAttribute(attribute).Equals(attname))
                    {
                        current.SetAttribute("value", value);
                    }
                }
            }
    3) double click on web browser and add that code :
    Code:
                Set_Text_TAG_INPUT("name", "firstname", "My First Name");
                Set_Text_TAG_INPUT("name", "secondname", "My Last Name");
                Set_Text_TAG_SELECT("name", "gender", "m");
                Set_Text_TAG_SELECT("name", "mm", "4");
                Set_Text_TAG_INPUT("name", "dd", "12");
                Set_Text_TAG_INPUT("name", "yyyy", "1990");
                Set_Text_TAG_INPUT("name", "yahooid", "YAHOOID");
                Set_Text_TAG_INPUT("name", "password", "password");
                Set_Text_TAG_INPUT("name", "passwordconfirm", "password");
                Set_Text_TAG_SELECT("name", "secquestion", "What is the first name of your favorite uncle?");
                Set_Text_TAG_INPUT("name", "secquestionanswer", "My uncle");
                Set_Text_TAG_SELECT("name", "secquestion2", "What was the last name of your best childhood friend?");
                Set_Text_TAG_INPUT("name", "secquestionanswer2", "Jack");
                Set_Text_TAG_INPUT("name", "captchaAnswer", "Lets see this");
    And finally if you want to press Create Account button add this function :
    Code:
            private void Click_Search(string attribute, string attname)
            {
                HtmlElementCollection htmlec = webBrowser1.Document.GetElementsByTagName("input");
    
                foreach (HtmlElement current in htmlec)
                {
                    if (current.GetAttribute(attribute).Equals(attname))
                    {
                        current.InvokeMember("click");
                    }
                }
            }
    And inside webBrowser1_DocumentCompleted , add :
    Code:
    Click_Search("name", "IAgreeBtn");
    Now run the application and watch the magic

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts