title: Selenium Automatic element click returns null
body: <p>I have written a automation test case in selenium to test login page and should click forgot password link.Browser opens and goes to the url given but forgot password link isn't automatically clicking ,Can someone tell whats the problem with my code.</p>
  
  <p><strong>BaseCode</strong> </p>
  
  <pre><code>public class Forgetpsw {
  
      WebDriver driver;
  
      @BeforeTest
      public void Browseropen() throws Exception {
          Browsers startup=new  Browsers();
          startup.Initiating();
      }
  
      @Test
      public void Forget(String username) throws Exception{
          driver.findElement(By.xpath("//*[text()='Forgot Password?']")).click();
          Thread.sleep(3000L);
          driver.findElement(By.xpath("//*[@placeholder='User ID'][@id='forgotPasswordForm:j_idt13:0:username']")).sendKeys(username);
      }
  }
  </code></pre>
  
  <p><strong>Browsers.java</strong></p>
  
  <pre><code>public class Browsers {
      public  WebDriver driver;
  
      public void Initiating() throws IOException {
          Properties prop= new Properties();
          InputStream fis = new FileInputStream("D:\\Workspace\\TMS\\selenium\\ZLive\\src\\datadriven.properties");
          prop.load(fis);
  
  
          System.out.println("Initiating Browser");
  
          if (prop.getProperty("browser").equals("firefox"))
          {
              driver=new FirefoxDriver();
          }
          else
          {
              System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe");
              driver = new ChromeDriver();
          }
          driver.manage().window().maximize();
          driver.get(prop.getProperty("url"));
      }
  }
  </code></pre>
  
  <p><strong>data.properties</strong></p>
  
  <pre><code>browser=firefox
  url=http://abcd.xxx.in/login
  username=32131
  pasword=32131
  </code></pre>
  
  <p>Console :</p>
  
  <pre><code>[TestNG] Running:
    C:\Users\ds\AppData\Local\Temp\testng-eclipse-42991103\testng-customsuite.xml
  
  Initiating Browser
  
  ===============================================
      Default test
      Tests run: 0, Failures: 0, Skips: 0
  ===============================================
  
  
  ===============================================
  Default suite
  Total tests run: 0, Failures: 0, Skips: 0
  ===============================================
  </code></pre>
  
  <p><strong>HTML CODE</strong></p>
  
  <pre><code>&lt;div class="loginRelative" id="secondDiv"&gt;&lt;label class="loginText"&gt;Transport Management System&lt;/label&gt;
            &lt;div class="logo-div"&gt;
              &lt;div class="loginimageBgStyle"&gt;&lt;img src="images/indexImg.png" /&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="absoluteLeft"&gt;&lt;/div&gt;
            &lt;div class="absoluteRight"&gt;&lt;/div&gt;&lt;span id="loginForm:loginPanel"&gt;&lt;div id="loginForm:messages" class="ui-messages ui-widget errorValidationStyle" aria-live="polite"&gt;&lt;/div&gt;
  
            &lt;div class="controls loginTextbox" id="thirdDiv"&gt;&lt;div id="loginForm:j_idt16:0:j_idt18" class="ui-outputpanel ui-widget"&gt;&lt;input id="loginForm:j_idt16:0:username" name="loginForm:j_idt16:0:username" type="text" placeholder="User ID" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" /&gt;&lt;script id="loginForm:j_idt16:0:username_s" type="text/javascript"&gt;PrimeFaces.cw("InputText","widget_loginForm_j_idt16_0_username",{id:"loginForm:j_idt16:0:username",widgetVar:"widget_loginForm_j_idt16_0_username"});&lt;/script&gt;&lt;/div&gt;
            &lt;/div&gt;&lt;div id="loginForm:j_idt16:0:j_idt20" aria-live="polite" class="ui-message ui-helper-hidden"&gt;&lt;/div&gt;&lt;script id="loginForm:j_idt16:0:j_idt20_s" type="text/javascript"&gt;$(function(){PrimeFaces.cw("Message","widget_loginForm_j_idt16_0_j_idt20",{id:"loginForm:j_idt16:0:j_idt20",widgetVar:"widget_loginForm_j_idt16_0_j_idt20",target:"loginForm:j_idt16:0:username"});});&lt;/script&gt;  
  
            &lt;div class="controls loginPassword"&gt;&lt;div id="loginForm:j_idt16:0:j_idt22" class="ui-outputpanel ui-widget"&gt;&lt;input id="loginForm:j_idt16:0:password" name="loginForm:j_idt16:0:password" type="password" class="ui-inputfield ui-password ui-widget ui-state-default ui-corner-all" placeholder="******" /&gt;&lt;script id="loginForm:j_idt16:0:password_s" type="text/javascript"&gt;$(function(){PrimeFaces.cw("Password","widget_loginForm_j_idt16_0_password",{id:"loginForm:j_idt16:0:password",widgetVar:"widget_loginForm_j_idt16_0_password"});});&lt;/script&gt;&lt;/div&gt;
                              &lt;!-- &amp;lt;p:keyboard id="" value="" &amp;gt;
  
                  &amp;lt;/p:keyboard&amp;gt; --&gt;
                          &lt;/div&gt;&lt;div id="loginForm:j_idt16:0:j_idt24" aria-live="polite" class="ui-message ui-helper-hidden"&gt;&lt;/div&gt;&lt;script id="loginForm:j_idt16:0:j_idt24_s" type="text/javascript"&gt;$(function(){PrimeFaces.cw("Message","widget_loginForm_j_idt16_0_j_idt24",{id:"loginForm:j_idt16:0:j_idt24",widgetVar:"widget_loginForm_j_idt16_0_j_idt24",target:"loginForm:j_idt16:0:password"});});&lt;/script&gt;
  
            &lt;div&gt;&lt;a href="/forgotPassword" class="forgotPwdStyle"&gt;Forgot Password?&lt;/a&gt;
            &lt;/div&gt;
  
            &lt;div class="loginBtnBgStyle"&gt;&lt;button id="loginForm:j_idt28" name="loginForm:j_idt28" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only noBtnStyle" type="button"&gt;&lt;span class="ui-button-icon-left ui-icon ui-c loginBtnImg"&gt;&lt;/span&gt;&lt;span class="ui-button-text ui-c"&gt;ui-button&lt;/span&gt;&lt;/button&gt;&lt;script id="loginForm:j_idt28_s" type="text/javascript"&gt;PrimeFaces.cw("CommandButton","widget_loginForm_j_idt28",{id:"loginForm:j_idt28",widgetVar:"widget_loginForm_j_idt28"});&lt;/script&gt;&lt;button id="loginForm:loginButton" name="loginForm:loginButton" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only loginBtnStyle" onclick="return loginTms();;" type="button"&gt;&lt;span class="ui-button-text ui-c"&gt;Login&lt;/span&gt;&lt;/button&gt;&lt;script id="loginForm:loginButton_s" type="text/javascript"&gt;PrimeFaces.cw("CommandButton","widget_loginForm_loginButton",{id:"loginForm:loginButton",widgetVar:"widget_loginForm_loginButton"});&lt;/script&gt;
            &lt;/div&gt;&lt;/span&gt;&lt;script type="text/javascript"&gt;loginTms = function() {PrimeFaces.ab({s:'loginForm:j_idt30',f:'loginForm',u:'loginForm',pa:arguments[0]});}&lt;/script&gt;
  
            &lt;script&gt;
             function TMS_onLoginBtnClick(){
  
              //alert("localhostinnnn");
              var payroll = $("#payrollIframe").contents();
              payroll.find("#username").val(document.getElementById("loginForm:j_idt15:0:username").value);
              payroll.find("#password").val(document.getElementById("loginForm:j_idt15:0:password").value);
              payroll.find("#user_accounts")[0].submit();
              return false;
             }
  
  
             /**
              This method will be called from payroll 
              iframe after success full login
             */
             function loginSuccess(){
                //alert("logged in");
              //TODO: handle here
                loginTms();
             }
  
             function loginFail(){
  
              //TODO: handle here
             }
          &lt;/script&gt;
          &lt;iframe id="payrollIframe" src="http://localhost/GOPayroll/?source=1" style="opacity:0; height:1px; width:1px;"&gt;
          &lt;/iframe&gt;
  
            &lt;div class="logoutMsgStyle"&gt;
  
            &lt;/div&gt;
  
  
      &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>