title: How to use looping in selenium webdriver java when every next generated element will have different names
body: <p><a href="https://imageshack.com/i/n1eln6p" rel="nofollow">UI Project</a></p>
  
  <p>The scenario of the image above is the user can fill in all the details per partner, the user can add a maximum of 20 partners by clicking the add partner button, every time the user will add a new partner details the webpage elements will generate a new elements for example:</p>
  
  <p>given name textbox for partner 1 is = partner[0][person][given_name] .</p>
  
  <p>if the user adds another set of partner details the element for partner 2 given name will be: </p>
  
  <p>given name textbox for partner 2 is = partner[<a href="https://imageshack.com/i/n1eln6p" rel="nofollow">1</a>][person][given_name] .</p>
  
  <p>so every time the user adds a partner details the index for elements will increment. </p>
  
  <p>Here is my code im using selenium webdriver using java and hybrid automation framework. I want to use looping on this code, is it possible to use looping in this kind of framework? cause if i don't have to use loop, i have to write my action class like 20 times and i will need to find all the elements for each partner which is not logical thing to do. Please guide me. on how to make these code easier specially on making my code shorter.</p>
  
  <p>// Here's my Page Object repository (its where i store my web page elements) 
  // I have put a parameter (value) on my elements index </p>
  
  <pre><code>public class RegistrationPage extends BaseClass {
  
      private static WebElement element;
  
      public RegistrationPage(WebDriver driver){
          super(driver);
      }
  
    public static WebElement txtbx_GivenName(int value){
       try{
  
       element = driver.findElement(By.name("partner["+value+"][person][given_name]"));
       Log.info("Given name textbox found");
       }catch (Exception e){
       Log.error("Given name textbox is not found on the Register Page");
       throw(e);
   }
       return element;
   } 
  
   public static WebElement txtbx_LastName(int value){
       try{
       element = driver.findElement(By.name("partner["+value+"][person][last_name]"));
       Log.info("Last name textbox found");
       }catch (Exception e){
       Log.error("Last name textbox is not found on the Register Page");
       throw(e);
       }
       return element;
   } 
  
   public static WebElement txtbx_Email(int value){
       try{
       element = driver.findElement(By.name("partner["+value+"][person][email]"));
       Log.info("Email textbox found");
       }catch (Exception e){
       Log.error("Email textbox is not found on the Register Page");
       throw(e);
       }
       return element;
   } 
  
   public static WebElement txtbx_ContactNumber(int value){
       try{
       element = driver.findElement(By.name("partner["+value+"][contact_number]"));
       Log.info("Contact number textbox found");
       }catch (Exception e){
       Log.error("Contact number textbox is not found on the Register Page");
       throw (e);
       }
       return element;
   } 
  </code></pre>
  
  <p>// and so on.. for other fields</p>
  
  <p>Here is my action class (its where i put my action script and you will also see in this section is where i get my data, i get my data from excel)</p>
  
  <pre><code>public class RegisterPartnerDetails_Action {
  
      public static void Execute (int iTestCaseRow) throws Exception {
  
         int val = 0;
          String sGivenName = ExcelUtils.getCellData(iTestCaseRow, Constant.COL_GIVEN_NAME);
          Log.info("Given name picked from Excel is " + sGivenName);     
          com.businessname.pageobjects.RegistrationPage.txtbx_GivenName(val).sendKeys(sGivenName);
          Log.info("Given name entered in the Given name text box");
  
          String sLastName = ExcelUtils.getCellData(iTestCaseRow, Constant.COL_LAST_NAME);
          Log.info("Last name picked from Excel is " + sLastName);
          com.businessname.pageobjects.RegistrationPage.txtbx_LastName(val).sendKeys(sLastName);
          Log.info("Last name entered in the Lastname text box");
  
          String sEmail = ExcelUtils.getCellData(iTestCaseRow, Constant.COL_EMAIL);
          Log.info("email picked from Excel is " + sEmail);
          com.businessname.pageobjects.RegistrationPage.txtbx_Email(val).sendKeys(sEmail);
          Log.info("Email entered in the email text box");
  
          String sContactNumber = ExcelUtils.getCellData(iTestCaseRow, Constant.COL_CONTACT_NUMBER);
          Log.info("Contactnumber picked from Excel is " + sContactNumber);
      com.businessname.pageobjects.RegistrationPage.txtbx_ContactNumber(val).sendKeys(sContactNumber);
          Log.info("Contact number entered in the contact number text box");
          //etc for other details
   val++;
  </code></pre>
  
  <p>}
      }</p>
  
  <p>I'm using also modular framework, its where my main class is located. Correct me if im wrong im thinking that i will put my for loop here right?</p>
  
  <pre><code>@Test
    public void main() throws Exception {
  
       com.businessname.modules.SearchBusinessname_Action.Execute(iTestCaseRow);
       com.businessname.modules.InputAustralianBusinessNumber_Action.Execute(iTestCaseRow) 
  
  // Here is the registration script part, i will need to put for loop on this right?
  
       com.businessname.modules.RegisterPartnerDetails_Action.Execute(iTestCaseRow);
    }
  </code></pre>