title: Click on all hidden sublinks in a menu using a loop
body: <p>I am using WebDriver 2 with Java.
  I am testing a menu that has hidden sublinks that are visible once a user hovers over them.  I need to hover over the menu, click on each link within the menu, go the appropriate page, return back to the original page and repeat all the steps for the next link. I can do this using the following method which does that for each sublink separately. My goal is to create a method that will do all those steps using a loop, that can be re-used for similar menus. Here is the method that I have right now without a loop (I have created custom methods hoverOver and waitForElementVisibility).</p>
  
  <p>hoverOver is:</p>
  
  <pre><code>public void hoverOver(WebElement element){
  Actions builder = new Actions(driver);
  builder.moveToElement(element).build().perform();
  new WebDriverWait(driver,10);
  }
  </code></pre>
  
  <p>waitForElementVisibility is:</p>
  
  <pre><code>public void waitForElementVisibility(WebElement element){
  new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(element));
  }
  </code></pre>
  
  <p>And the method for menu and sublinks is(this is the method that I want to create as a loop):</p>
  
  <pre><code>public void checkLinksInTopMenu(WebElement menu, WebElement sublink1, 
  WebElement sublink2, WebElement sublink3){
  hoverOver(menu);
  waitForElementVisibility(sublink1);
  sublink1.click();
  driver.navigate().back();
  hoverOver(menu);
  waitForElementVisibility(sublink2);
  sublink2.click();
  driver.navigate().back();
  hoverOver(menu);
  waitForElementVisibility(sublink3);
  sublink3.click();
  driver.navigate().back();
  }
  </code></pre>
  
  <p>Please help me out, thank you in advance.</p>