title: For-loop for clicking web element
body: <p>I'm trying to loop the for loop 7 times where the webelement will be click 7 times only. Even if there are other commentsbutton element in the web page, the loop will ignore them and stop clicking. </p>
  
  <p>Currently, the script will still click on the webelement non-stop.</p>
  
  <pre><code> WebElement commentsbutton = (WebElement) comment.findElement(By.xpath("//button[contains(@class,'-cx-PRIVATE-PostInfo__commentsLoadMoreButton -cx-PRIVATE-PostInfo__commentsLoadMoreButtonEnabled')]")); //view all/ load more comments
  
  //click more comments
  for(int i = 0; i &lt; 7; i++) {
      //for (WebElement comments_element : commentsbutton) {
      commentsbutton.click(); //click on button if found
      Thread.sleep(3000); //pause for 5 seconds   
      System.out.println(commentsbutton);
      //}
  }
  </code></pre>