Automated filling of web form from a list in Python using Selenium
Question: This is the Selenium code in Python "sel.py" :-

    
    
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    
    driver.get('http://127.0.0.1:8000/employee/register/')
    
    employes = ['1', '2016-1-1', 'Tarun', 'Gupta', 'Male', '1995-12-7', 'Indian', 'Hinduism', 'General', 'O+', 'Single', '1122334455', 'diploma', 'Btech', 
                  'HMRITM','GGSIPU', '2016', 'distinction', '95', 'full time', 'Web Developer', 'Comp Science', '2017', '95000', '8700925621', '44087062', 
                  'gupta.tarun@gmail.com', 'Vasant Vihar', 'East delhi', 'Delhi', '110056']
    
    input = []
    input = driver.find_elements_by_xpath('//*[@id]')
    i = 0
    for xpaths in input:
        xpaths.send_keys(employes[i]) 
        print(employee[i])
        i += 1
    
    
    driver.find_element_by_xpath('//*[@id="Submit"]').click()
    

This is the Registration Form:-

[![enter image description
here](http://i.stack.imgur.com/DW68o.png)](http://i.stack.imgur.com/DW68o.png)

This is the HTML code but here the input tags are python variables as made
this in Django :-

    
    
    <form action="/employee/register/" method="post">{% csrf_token %}
            <div class="col-md-12 col-lg-12">
    
                <div id="col1" class="col-md-2 col-lg-2"></div>
                <div id="col2" class="col-md-4 col-lg-4">
                  <h4 class="text-center">Application Details</h4>
                    <fieldset class="form-group">
                            <label for="Applicationno">Application No.</label>
                            <!--<input type="number" class="form-control" id="Applicationno" name="Applicationno"
                            placeholder="Application No.">-->
                            {{appform.ApplicationNo}}
                    </fieldset>
    
                    <fieldset class="form-group">
                        <label for="applyon">Apply On</label>
                        <!--<input type="date" class="form-control" id="applyon" name="applyon">-->
                        {{appform.ApplyOn}}
                    </fieldset>
    
                </div>
                <div id="col3" class="col-md-6 col-lg-6">
    
                     <h4 class="text-center">Personal Details</h4>
                    <div class="form-inline">
                        <!--<select id="title1" name="title1" class="form-control">-->
                            <!--<option selected>Title</option>-->
                            <!--<option>Mr.</option>-->
                            <!--<option>Mrs.</option>-->
                            <!--<option>Ms.</option>-->
                        <!--</select>-->
                    <label for="firstName1"></label>
                        <!--<input id="firstName1" class="form-control" name="firstName1" type="text" placeholder="First name" >-->
                        {{empform.FirstName}}
                    <label for="lastName1"></label>
                        <!--<input id="lastName1" class="form-control" name="lastName1" type="text"  placeholder="Last name" >-->
                        {{empform.LastName}}
                   </div>
    
                   <br>
    
                    <div class="form-inline">
                    <label>Gender:
                        {{empform.Gender}}</label>
                        <!--<label for="Male" class="radio-inline">-->
                            <!--<input id="Male" name="Male" type="radio">Male</label>-->
    
                        <!--<label for="Female" class="radio-inline">-->
                            <!--<input id="Female" name="Female" type="radio">Female</label>-->
    
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
                    <label for="BirthDate">
                        Birth Date:
                        <!--<input id="BirthDate" name="BirthDate" type="date" class="form-control">-->
                        {{empform.BirthDate}}
                    </label>
                        </div>
    
                    <br>
                    <div class="form-inline">
                    <label for="Nationality">
                        Nationality:
                        <!--<input id="Nationality" class="form-control" name="Nationality" type="text"  placeholder="Nationality" >-->
                        {{empform.Nationality}}
                    </label>
    
                        &nbsp;
                        &nbsp;
                        &nbsp;
                    <label for="Religion">
                        Religion:
                        <!--<input id="Religion" class="form-control" name="Religion" type="text"  placeholder="Religion" >-->
                        {{empform.Religion}}
                    </label>
                     </div>
    
                    <br>
                    <div class="form-inline">
                    <label class="Category" for="Category">
                        {{empform.Category}}
                        <!--Category:-->
                        <!--<select id="Category" name="Category" class="form-control">-->
                            <!--<option selected="selected">GEN</option>-->
                            <!--<option>OBC</option>-->
                            <!--<option>SC</option>-->
                            <!--<option>ST</option>-->
                        <!--</select>-->
                    </label>
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       &nbsp;&nbsp;&nbsp;&nbsp;
                    <label for="BloodGroup">
                        Blood Group:
                        <!--<input id="BloodGroup" class="form-control" name="BloodGroup" type="text"  placeholder="Blood Group" >-->
                        {{empform.BloodGroup}}
                    </label>
                        </div>
    
                    <br>
    
                    <div class="form-inline">
                    <label class="MaritalStatus" for="MaritalStatus">
                        {{empform.MaritalStatus}}
                        <!--Marital Status:-->
                        <!--<select id="MaritalStatus" name="MaritalStatus" class="form-control">-->
                            <!--<option selected="selected">Single</option>-->
                            <!--<option>Married</option>-->
                        <!--</select>-->
                    </label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="AdhaarCardNo" for="AdhaarCardNo">
                        Adhaar Card No.:
                        <!--<input type="number" class="form-control" id="AdhaarCardNo" name="AdhaarCardNo" placeholder="Adhaar card No.">-->
                        {{empform.AdhaarCardNo}}
                    </label>
                        </div>
    
                </div>
    
            </div>
    
    
            <div class="col-md-12 col-lg-12" style="margin-top:5px;">
    
                <div class="col-md-5 col-lg-5">
    
                    <div class="row" style="padding:5px 5px 5px 5px;">
    
                        <div id="col4" class="col-md-12 col-lg-12">
    
                              <h4 class="text-center">Education & Qualification Details</h4>
                              <div class="form-inline">
                            <label class="Level" for="Level">
                          Level:
                                {{eduform.Level}}
                        <!--<select id="Level" name="Level" class="form-control">-->
                            <!--<option selected="selected">Diploma</option>-->
                            <!--<option>Bachelors</option>-->
                            <!--<option>Masters</option>-->
                            <!--<option>Professional</option>-->
                        <!--</select>-->
                    </label>
                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="Degree">
                        Degree:
                        <!--<input type="text" id="Degree" name="Degree" placeholder="Degree" class="form-control">-->
                        {{eduform.Degree}}
                    </label>
                                  </div>
                            <br>
                <div class="form-inline">
                    <label class="College">
                        College:
                        <!--<input type="text" id="College" name="College" placeholder="College" style="width:350px;" class="form-control">-->
                        {{eduform.College}}
                    </label>
                  </div>
                    <br>
                            <div class="form-inline">
                    <label class="University">
                        University:
                        <!--<input type="text" id="University" name="University" placeholder="University" style="width:350px;" class="form-control">-->
                        {{eduform.University}}
                    </label>
                                </div>
                    <br>
    
             <div class="form-inline">
                    <label class="YearOfQualification">
                        Year Of Qualification:
                        <!--<input type="date" id="YearOfQualification" name="YearOfQualification" class="form-control">-->
                        {{eduform.YearOfPassing}}
                    </label>
                 </div>
                            <br>
                     <div class="form-inline">
                    <label class="Class" for="Class">
                        Class:
                        {{eduform.Class}}
                        <!--<select id="Class" name="Class" class="form-control">-->
                            <!--<option selected="selected">Distinction</option>-->
                            <!--<option>First</option>-->
                            <!--<option>Second</option>-->
                            <!--<option>Third</option>-->
                        <!--</select>-->
                    </label>
                    &nbsp;
                    <label class="Percentage">
                        Percentage %:
                        <!--<input type="number" id="Percentage" name="Percentage" placeholder="Percentage" class="form-control">-->
                        {{eduform.Percentage}}
    
                    </label>
    
                        </div>
                </div>
                    </div>
                    <div class="row" style="padding:5px 5px 5px 5px;">
    
                        <div id="col5" class="col-md-12 col-lg-12">
    
                            <h4 class="text-center">Official Details</h4>
                            <!--<label class="EmpCode">-->
                        <!--Emp Code:-->
                        <!--<input type="number" id="EmpCode" name="EmpCode" placeholder="Emp Code" class="form-control">-->
                    <!--</label>-->
                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="EmpType" for="EmpType">
                        Emp Type:
                        {{offform.EmpType}}
                        <!--<select id="EmpType" name="EmpType" class="form-control">-->
                            <!--<option selected="selected">Full Time</option>-->
                            <!--<option>Part Time</option>-->
                        <!--</select>-->
                    </label>
                    <br><br>
                     <label class="Designation">
                        Designation:
                        <!--<input type="text" id="Designation" name="Designation" placeholder="Designation" class="form-control">-->
                         {{offform.Designation}}
                    </label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="Department">
                        Department:
                        <!--<input type="text" id="Department" name="Department" placeholder="Department" class="form-control">-->
                        {{offform.Department}}
                    </label>
                    <br><br>
                   <label class="JoiningOn">
                        Joining On:
                        <!--<input type="date" id="JoiningOn" name="JoiningOn" class="form-control">-->
                       {{offform.JoiningOn}}
                    </label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="Salary">
                        Salary:
                        <!--<input type="number" id="Salary" name="Salary" class="form-control">-->
                        {{offform.Salary}}
                    </label>
    
                        </div>
    
                    </div>
    
                </div>
                <div class="col-md-7 col-lg-7">
    
                     <div class="row" style="padding:5px 5px 5px 5px;">
    
                        <div id="col6" class="col-md-12 col-lg-12">
    
                            <h4 class="text-center">Contact Details</h4>
                                            <div class="form-inline">
                             <label class="Mobile">
                        Mobile:
                        <!--<input type="number" id="Mobile" name="Mobile" placeholder="Mobile" class="form-control">-->
                                 {{contform.MobileNo}}
                    </label>
    
                                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       &nbsp;&nbsp;&nbsp;&nbsp;
    
                     <label class="PhoneNo" for="PhoneNo">
                        Phone No.:
                        <!--<input type="number" id="PhoneNo" name="PhoneNo" placeholder="Phone No." class="form-control">-->
                         {{contform.PhoneNo}}
                    </label>
                                                </div>
                    <br><br>
    
                     <div class="form-inline">
                    <label class="Email" for="Email">
                        Email:
                        <!--<input type="email" id="Email" name="Email" placeholder="Email" class="form-control">-->
                        {{contform.EmailId}}
                    </label>
    
                         </div>
    
                    <br><br>
                    <label class="Address" for="Address">
                        Address:
                        <!--<textarea id="Address" name="Address" placeholder="Address" rows="5" cols="70" class="form-control"></textarea>-->
                        {{contform.AddressLine}}
                    </label>
                    <br><br>
                            <div class="form-inline">
                     <label class="City" for="City">
                        City:
                        <!--<input type="text" id="City" name="City" placeholder="City" class="form-control">-->
                         {{contform.City}}
                    </label>
    
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
                     <label class="State">
                        State:
                        <!--<input type="text" id="State" name="State" placeholder="State" class="form-control">-->
                         {{contform.State}}
                    </label>
                                </div>
                            <br>
                            <div class="form-inline">
                    <label class="PinCode">
                        PinCode:
                        <!--<input type="number" id="PinCode" name="PinCode" placeholder="PinCode" class="form-control">-->
                        {{contform.PinCode}}
                    </label>
                          </div>
    
                        </div>
    
                    </div>
                    <div class="row" style="padding:5px 5px 5px 5px;">
    
                        <div class="col-md-12 col-lg-12" style="margin:60px 10px 10px 10px;">
    
                           <div class="form-inline text-right">
                            <input type="submit" id="Submit" name="Submit" class="btn btn-success btn-lg" >
                            <input type="submit" id="Clear" name="Clear" value="Clear" class="btn btn-warning btn-lg"
                                   style="margin-left:20px;">
                            <input type="submit" id="Cancel" name="Cancel" value="Cancel" class="btn btn-danger btn-lg"
                             style="margin-left:20px;">
    
                           </div>
                        </div>
    
                    </div>
    
                </div>
    
            </div>
           </form>
    

I want to fill all the WebElements in form from the text in the list
"employes" in "sel.py" file , but i am getting this error :-

[![enter image description
here](http://i.stack.imgur.com/aD1uj.png)](http://i.stack.imgur.com/aD1uj.png)

I don't know how to fix this error , any help is appreciated ! thanks in
advance.


Answer: 
    from selenium import webdriver
    from selenium.webdriver.support.select import Select
    
    
    driver = webdriver.Chrome()
    
    driver.get('http://127.0.0.1:8000/employee/register/')
    
    
    
    employees = { 'id_ApplicationNo':'1', 'id_ApplyOn':'2016-1-1', 'id_FirstName':'Tarun',
                'id_LastName':'Gupta', 'id_Gender':'Male', 'id_BirthDate':'1995-12-7', 'id_Nationality':'Indian',
                'id_Religion':'Hinduism', 'id_Category':'General', 'id_BloodGroup':'O+', 'id_MaritalStatus':'single',
                'id_AdhaarCardNo':'1122334455', 'id_Level':'diploma', 'id_Degree':'Btech', 'id_College':'HMRITM',
                'id_University':'GGSIPU', 'id_YearOfPassing':'2016', 'id_Class':'first', 'id_Percentage':'95',
                'id_EmpType':'part time', 'id_Designation':'Web Developer', 'id_Department':'Comp Science',
                'id_JoiningOn':'2017-3-3', 'id_Salary':'95000', 'id_MobileNo':'8700925621', 'id_PhoneNo':'44087062',
                'id_EmailId':'gupta.tarun@gmail.com', 'id_AddressLine':'Vasant Vihar', 'id_City':'East delhi',
                'id_State':'Delhi', 'id_PinCode':'110056' }
    
    for key, value in employees.items():
        element = driver.find_element_by_id(key)
        if element.tag_name == "select":
           select = Select(element)
           select.select_by_visible_text(value)
        else:
           element.send_keys(value)
    
    
    driver.find_element_by_id('Submit').click()
    

