How To handle Registration Form If the form is dynamic

Hello Everyone I Want To Ask How To handle an Form if There can show more than one so i can add per person maybe 5 maybe 3 so the form will showing with the count i add person i already use while do but i still stuck when i adding person


this is the form sample, thanks for the help

Does the text, “Adult Traveller x”, appear before every Form set?

boolean hasDone = false;
int counter = 1;

while (!hasDone) {
   if (WebUI.verifyTextPresent("Adult Traveller ${counter}", false)) {
      // fill in form
   } else {
      hasDone = true;
   }
   counter++
}

I am making an assumption that the Forms are given an array style identification.

There Had 3 Passager Adult, Infant, and Child so id will add up the text will following example 1 Adult Traveler , 2 Adult Traveler, 1 Child Traveler so The Text Will Follow up when i adding pasanger type

You still might be able to do something similar if the Form sets have an array style of identification (maybe the first Traveler’s Last Name textbox has an attribute like name=box__0_lastname, the second Traveler’s Last Name textbox is like name=box__1_lastname and the third is like name=box__2_lastname. You can check if the next “lastname” textbox element exists and if it does, fill in the form. You will have to check the HTML if this is the case.

Okay Let Me Try It, Thanks For the Information

Another thought if the Form set has a similar pattern at a “Form” level (or maybe just above). Then you could collect that level in a List<WebElement> and get the number of Form sets. With that, you could just do a For loop with or without a Case block (with each block calling a Keyword) to fill in the form.

Maybe like:
WebDriver driver = DriverFactory.getWebDriver();
List<WebElement> formItems = driver.findElements(By.xpath('your common path here'));
int maxForms = formItems.size(); 
Loop:
for (int irow = 0; irow < maxForms; irow++)
{