title: How to submit a Form using Selenium in Java
body: <p>I am using <code>Selenium WebDriver</code> to automate a system. Language is <code>Java</code>. I have done most of the things but I am stuck at one point. I need to submit a Form that contains Username, Password and Re-Entering Password fields. But when I fill them(using selenium) and click the Create Account button It didn't work.</p>
  
  <blockquote>
    <p>Here is the code,</p>
  </blockquote>
  
  <pre><code>    System.setProperty("webdriver.chrome.driver", "./ChromeDriver/chromedriver.exe");
  
      WebDriver driver = new ChromeDriver();
      driver.get("URL Here");
  
      WebElement element9 = driver.findElement(By.id("accountname"));
      element9.sendKeys(username);
  
      WebElement element10 = driver.findElement(By.id("password"));
      element10.sendKeys(password);
  
      WebElement element12 = driver.findElement(By.id("reenter_password"));
      element12.sendKeys(password);
  </code></pre>
  
  <blockquote>
    <p>I used these methods to submit the form. But none of them worked.</p>
  </blockquote>
  
  <pre><code>    element12.sendKeys(Keys.ENTER); //method 1
  
      WebElement element11 = driver.findElement(By.linkText("Complete Sign-up"));
      element11.click(); //method 2
  
      ((JavascriptExecutor)driver).executeScript("javascript:CompleteCreateAccount();"); //method 3
  
      WebElement element13 = driver.findElement(By.xpath("//a[@id='createAccountButton']/span"));
      element13.click(); //method 4
  
      element13.submit(); //method 5
  
      JavascriptExecutor executor = (JavascriptExecutor)driver;
      executor.executeScript("arguments[0].click();", element13); //method 6
  </code></pre>
  
  <blockquote>
    <p>Form HTML got from Inspect Element,</p>
  </blockquote>
  
  <pre><code>&lt;div class="leftcol"&gt;
  &lt;div id="error_display" style="display: none;"&gt;&lt;/div&gt;
      &lt;div class="checkout_content_box" id="cart_area"&gt;
          &lt;form id="create_account" name="create_account" action="" onsubmit="CompleteCreateAccount(); return false; " method="POST"&gt;
              &lt;input type="hidden" name="lt" id="lt" value="0"&gt;
              &lt;div id="account_form_box"&gt;
                  &lt;div class="join_form"&gt;
                      &lt;div class="form_row"&gt;
                          &lt;div class="form_area"&gt;
                              &lt;label for="accountname"&gt;Create a Steam account name&lt;/label&gt;
                              &lt;input type="text" maxlength="64" name="accountname" id="accountname" onchange="CheckAccountNameAvailability();"&gt;
                          &lt;/div&gt;
                          &lt;div class="form_notes"&gt;
                              &lt;br&gt;
                              &lt;span class="input_note"&gt;&lt;a href="javascript:CheckAccountNameAvailability();"&gt;Check availability&lt;/a&gt;&lt;/span&gt;
                              &lt;span id="accountname_availability" style="display: none;"&gt;&lt;/span&gt;
                          &lt;/div&gt;
                      &lt;div style="clear: left;"&gt;&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div id="form_row_choose_suggested_name" class="form_row" style="display: none;"&gt;
                      &lt;div class="form_area"&gt;
                          &lt;label for="choose_accountname"&gt;Available account names&lt;/label&gt;&lt;br&gt;
                          &lt;select id="choose_accountname" name="choose_accountname" size="3" onchange="UpdateAccountName( this.value );"&gt;
                              &lt;option id="suggested_name_1"&gt;&lt;/option&gt;
                              &lt;option id="suggested_name_2"&gt;&lt;/option&gt;
                              &lt;option id="suggested_name_3"&gt;&lt;/option&gt;
                          &lt;/select&gt;
                      &lt;/div&gt;
                      &lt;div class="form_notes"&gt;
                          &lt;br&gt;
                          &lt;span class="choose_accountname_description"&gt;Select one or try again with another name of your choice&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div style="clear: left;"&gt;&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="rule"&gt;&lt;/div&gt;
                  &lt;div class="form_row"&gt;
                      &lt;div class="form_area"&gt;
                          &lt;label for="password"&gt;Choose a password&lt;/label&gt;
                          &lt;input type="password" maxlength="64" name="password" id="password" onkeyup="CheckPasswordStrength()" autocomplete="off"&gt;
                      &lt;/div&gt;
                      &lt;div class="form_notes"&gt;
                          &lt;div id="password_tag" class="password_tag"&gt;&amp;nbsp;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div style="clear: left;"&gt;&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form_row"&gt;
                      &lt;div class="form_area"&gt;
                          &lt;label class="reenter_row" for="reenter_password"&gt;Re-enter password&lt;/label&gt;
                          &lt;input type="password" maxlength="64" name="reenter_password" id="reenter_password" onkeyup="ReenterPasswordChange()" autocomplete="off"&gt;
                      &lt;/div&gt;
                      &lt;div class="form_notes"&gt;
                          &lt;br&gt;
                          &lt;div id="reenter_tag" class="password_tag"&gt;&amp;nbsp;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div style="clear: left;"&gt;&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="rule"&gt;&lt;/div&gt;
  
                  &lt;div class="form_row"&gt;
                      &lt;div id="priv_and_sub"&gt;
                          &lt;a id="createAccountButton" class="btnv6_blue_hoverfade btn_medium" href="javascript:CompleteCreateAccount();" style="float: right;"&gt;
                              &lt;span&gt;Complete Sign-up&lt;/span&gt;
                          &lt;/a&gt;
  
                          &lt;div style="clear: right;"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div id="ssa_submit"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <blockquote>
    <p>And also I need to say when I click <code>Create Account button</code> manually it is working. But using selenium It is not working and pass this message</p>
    
    <p>The account name you have chosen is not available. Please choose
    another name. The password you entered is not allowed. Please select a
    different password, with at least 8 characters.</p>
    
    <p><strong>But username and passwords are okay. Nothing wrong. Because when I
    click it manually It is working with that username and password.</strong></p>
  </blockquote>