title: Selenium> How to call onClick javascript function using Selenium Webdriver
body: <p>I have came across one issue where I am trying to submit a form with the valid credentials. But due to some security checks which have been implemented on the form, I am unable to submit the form. On further analysis, I found that the onClick Javascript function has been implemented while submitting the form. Could anyone suggest, How to submit the form in such a scenario. </p>
  
  <pre><code>package erewards2;
  
  import java.util.concurrent.TimeUnit;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.firefox.FirefoxDriver;
  
  public class login_sib2 {
  
      public static void main(String[] args) {
  
          FirefoxDriver d1 = new FirefoxDriver();
  
                  d1.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                  d1.get("https://sib2.erewardsredeem.com/fm/customer.html?action=login2");  
               WebElement e1 = d1.findElement(By.id("memberid"));
                   e1.sendKeys("harshcse30");
                   WebElement e2 = d1.findElement(By.id("memberpwd"));
                           e2.sendKeys("Ciquser2");
                 e2.submit();
  
               // TODO Auto-generated method stub
  
                  //close Firefox
                  d1.close();
  
                  // exit the program explicitly
                  System.exit(0);
  
      }
  
  }
  </code></pre>
  
  <p>Another variation of the above code with changed property values for the form element is mentioned below:</p>
  
  <pre><code>package erewards2;
  
  import java.util.concurrent.TimeUnit;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.firefox.FirefoxDriver;
  
  public class login_sib2 {
  
      public static void main(String[] args) {
  
          FirefoxDriver d1 = new FirefoxDriver();
  
                  d1.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                  d1.get("https://sib2.erewardsredeem.com/fm/customer.html?action=login2");  
               WebElement e1 = d1.findElement(By.id("showmemberid"));
                   e1.sendKeys("harshcse30");
                   WebElement e2 = d1.findElement(By.id("showmemberpwd"));
                           e2.sendKeys("Ciquser2");
                 e2.submit();
  
               // TODO Auto-generated method stub
  
                  //close Firefox
                  d1.close();
  
                  // exit the program explicitly
                  System.exit(0);
  
      }
  
  }
  </code></pre>
  
  <p>The form which I am thinking to automate is:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
          &lt;meta http-equiv="X-Frame-Options" content="deny" /&gt;
          &lt;meta http-equiv="Cache-Control" content="max-age=0, no-cache, no-store, must-revalidate" /&gt;
          &lt;meta http-equiv="Pragma" content="no-cache" /&gt;
          &lt;meta http-equiv="Expires" content="-1" /&gt;
          &lt;title&gt; Login&lt;/title&gt;
          &lt;link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"/&gt;
          &lt;script type="text/javascript" src="/fm/js/login.js"&gt;&lt;/script&gt;
          &lt;script src="/fm/js/security/pbkdf2.js"&gt;&lt;/script&gt;
          &lt;script src="/fm/js/security/aes.js"&gt;&lt;/script&gt;
          &lt;link rel="stylesheet" href="/fm/styles/style.css" type="text/css" media="screen"/&gt;
          &lt;link rel="stylesheet" href="/fm/styles/forms.css" type="text/css" media="screen"/&gt;
          &lt;script type="text/javascript"&gt;
              window.history.forward();
              function noBack() {
                  window.history.forward();
              }
          &lt;/script&gt;
      &lt;/head&gt;
  
  
      &lt;script type="text/javascript"&gt;
          window.onload = function () {
              disableAutocompleteForAdmin();
          }
      &lt;/script&gt;
  
      &lt;body ondragstart="return false;" ondrop="return false;"&gt;
          &lt;!--Start wrapper--&gt;
          &lt;div class="wrapper"&gt;
              &lt;!--Start Header--&gt;
              &lt;div class="header"&gt;
                  &lt;div class="logoholder"&gt;&lt;a id="home" href="user.html?action=login"&gt;&lt;/a&gt;&lt;/div&gt;
                  &lt;div class="partner_logoblock"&gt;&lt;img src="images/partner_logo.jpg"/&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;!--End Header--&gt;
              &lt;!--Start Main Container--&gt;
              &lt;div class="maincontainer"&gt;
                  &lt;!--Start Inner Container--&gt;
                  &lt;div class="innercontainer"&gt;
                      &lt;!--Start Login--&gt;
                      &lt;div class="logincontainer"&gt;
                          &lt;form action="user.html?action=checkuser" method="POST" id="adminlogin" autocomplete="off" &gt;  
                              &lt;input type="hidden" name="_csrf" value="hzHmgJEwGgZiUP2cJO8P"/&gt;
  
                                  &lt;input type="hidden" class="inputfiled" id="username" value="" name="email" maxlength="64" autocomplete="off"/&gt;
  
  
                                  &lt;input  type="hidden" class="inputfiled" id="password" value="" name="password" maxlength="32" autocomplete="off" /&gt;
  
  
                          &lt;/form&gt;
                          &lt;h2&gt;Admin / Merchant Login&lt;/h2&gt;
                          &lt;dl&gt;
  
                              &lt;dt&gt;User Name&lt;/dt&gt;
                              &lt;dd&gt;
                                  &lt;input type="text" class="inputfiled" id="showusername" value="" name="showusername" maxlength="64" autocomplete="off"/&gt;
                              &lt;/dd&gt;
  
                              &lt;dt&gt;Password&lt;/dt&gt;
                              &lt;dd&gt;
                                  &lt;input  type="password" class="inputfiled" id="showpassword" value="" name="showusername" maxlength="32" autocomplete="off" /&gt;
                              &lt;/dd&gt;
  
  
                              &lt;dd&gt;
                                  &lt;input name="submit" type="submit" value="Login" class="loginbtn" onclick="callvalidation();" /&gt;
                                  &lt;a href="user.html?action=resetp"&gt;Forgot Password?&lt;/a&gt;
                              &lt;/dd&gt;
                          &lt;/dl&gt;
                          &lt;input type="hidden" name="st" id="st" value="EE4F02F7EB9B81C3D07FDA36F5A1D7C38F073A7C3DFE3802584F3835037B820A" /&gt;
  
                          &lt;div class="clearfix"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;!--End Login--&gt;
                  &lt;/div&gt;
                  &lt;!--End Inner Container--&gt;
              &lt;/div&gt;
              &lt;!--End Main Container--&gt;
          &lt;/div&gt;
          &lt;!--End wrapper--&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  
  
  
  
   &lt;link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" /&gt;
       &lt;meta http-equiv="X-Frame-Options" content="deny" /&gt;
  </code></pre>