title: Why i can't login on Instagram using pure JS?
body: <p>For study purposes I'm trying to make an automated login on the web version of Instagram (<a href="https://www.instagram.com/accounts/login/" rel="nofollow noreferrer">https://www.instagram.com/accounts/login/</a>).</p>
  
  <p>I thought the task would be easily achieved by just filling out the username and password fields, and then submitting the form; however it's not working, the form is submited with </p>
  
  <p>These are the elements involved:</p>
  
  <pre><code>&lt;input class="_2hvTZ pexuQ zyHYP" aria-label="Phone number, username, or email" aria-required="true" autocapitalize="off" autocorrect="off" maxlength="75" name="username" type="text" value=""&gt;
  &lt;input class="_2hvTZ pexuQ zyHYP" aria-label="Password" aria-required="true" autocapitalize="off" autocorrect="off" name="password" type="password" value=""&gt;   
  &lt;button class="sqdOP L3NKy y3zKF" disabled="" type="submit"&gt;&lt;div class="                  Igw0E IwRSH eGOV_ _4EzTm                                                                                                              "&gt;Log In&lt;/div&gt;&lt;/button&gt;
  </code></pre>
  
  <p>So here is the code I'm using to fill the elements and submit the form:</p>
  
  <pre><code>document.getElementsByName('username')[0].value = 'myusername';
  document.getElementsByName('password')[0].value = 'mypassword';
  document.getElementsByTagName('button')[0].removeAttribute("disabled");
  document.getElementsByTagName('button')[0].click();
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.getElementsByName('username')[0].value = 'myusername';
  document.getElementsByName('password')[0].value = 'mypassword';
  document.getElementsByTagName('button')[0].click();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input class="_2hvTZ pexuQ zyHYP" aria-label="Phone number, username, or email" aria-required="true" autocapitalize="off" autocorrect="off" maxlength="75" name="username" type="text" value=""&gt;
  &lt;input class="_2hvTZ pexuQ zyHYP" aria-label="Password" aria-required="true" autocapitalize="off" autocorrect="off" name="password" type="password" value=""&gt;
  &lt;button class="sqdOP L3NKy y3zKF" disabled="" type="submit"&gt;&lt;div class="                  Igw0E IwRSH eGOV_ _4EzTm"&gt;Log In&lt;/div&gt;&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The first two lines would fill the fields and fourth line would submit the form; somehow this won't work. Actually even the lines that fill the fields don't seem to work properly, because when i submit the form, i can see no field was sent to the server.</p>
  
  <p>It seems the problem is related to something about React, but why is my code not working? It should work as it's pure JavaScript; what am I missing here?</p>
  
  <p><a href="https://i.stack.imgur.com/biqgk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/biqgk.jpg" alt="enter image description here"></a></p>