title: Run Java code in loop in Selenium Webdriver
body: <p>I have two button with text "x" and they both have same cssSelector <code>a.aui-button.aui-button-link.aui-restfultable-delete.aui-restfultable-delete-small</code></p>
  
  <p>The code below is able to click on the first "x", however fails because there is a pop up window asking for confirm to delete.</p>
  
  <p>I want the code to click on first "x" and than click on "Delete" to confirm on the pop up window and repeat for the second "x". The cssSelector for "Delete" in Pop up window is <code>aui-button.js-confirm-action-button</code></p>
  
  <p>E.g. (Screenshot)</p>
  
  <pre><code>//Delete all existing Request Types
      List&lt;WebElement&gt; allele = driver.findElements(By.cssSelector("a.aui-button.aui-button-link.aui-restfultable-delete.aui-restfultable-delete-small"));
  
      // Looping through the elements using for-each loop
      for(WebElement eachEle : allele) {
          // Checking whether the element is enabled or not
          if(eachEle.isEnabled()) {
              eachEle.click();
          }
      }
  </code></pre>
  
  <p>Any Suggestion how can I write code to do this? Check Image here to get an idea of what I am trying to do <a href="http://i.stack.imgur.com/hG2K4.png" rel="nofollow">Example Image</a></p>