title: python autofill form in a webpage
body: <p>I am trying to fill a form in a webpage that has a single text box and a send button the html looks like this</p>
  
  <pre><code>&lt;form class="form-horizontal"&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-md-12"&gt;
                                  &lt;div id="TextContainer" class="textarea-container"&gt;
                                      &lt;textarea id="Text" rows="5" maxlength="700" class="form-control remove-border" style="background:none;"&gt;&lt;/textarea&gt;
                                  &lt;/div&gt;&lt;button id="Send" class="btn btn-primary-outline" type="button" onclick="SendMessage()" style="margin-top:10px" data-loading-text="Loading..."&gt;&lt;span class="icon icon-pencil"&gt;&lt;/span&gt; Send&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
  </code></pre>
  
  <p>I tried to use mechanize to submit the form with this code</p>
  
  <pre><code>import re
  from mechanize import Browser
  
  br = Browser()
  response=br.open("https://abcd.com/")
  for f in br.forms():
      if f.attrs['class'] == 'form-horizontal':
          br.form = f
  text = br.form.find_control(id="Text")
  text.value = "something"
  br.submit()
  </code></pre>
  
  <p>The code runs without an error, but no submission is happening , how do I do it? </p>
  
  <p>Here is the SendMessage function</p>
  
  <pre><code>function SendMessage() {
      var text = $('#Text').val();
      var userId = $('#RecipientId').val();
      if (text.trim() === "")
      {
          $('#TextContainer').css('border-color', 'red');
      }
      else if (new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(text))
      {
          $('#TextContainer').css('border-color', 'red');
          $('#message').html("Links are not allowed in messages");
      }
      else
      {
          $('#Send').button('loading');
          $.ajax(
          {
              url: '/Messages/SendMessage',
              type: 'POST',
              cache: false,
              data:
              {
                  __RequestVerificationToken: $('&lt;input name="__RequestVerificationToken" type="hidden" value="CfDJ8MQSRebrM95Pv2f7WNJmKQWGnVR66zie_VVqFsquOCZLDuYRRBPP1yzk_755VDntlD3u0L3P-YYR0-Aqqh1qIjd09HrBg8GNiN_AU48MMlrOtUKDyJyYCJrD918coQPG0dmgkLR3W85gV6P4zObdEMw" /&gt;').attr('value'),
                  userId: userId,
                  text: text
              }
  
          });
      }
  
  }
  </code></pre>