-3
public WebDriver Loopthisstuff (Webdriver driver, int X) {
   additem.click();
   WebElement answerX = driver.findElement(By.id("item_rowX_txt"));
   answerX.sendKeys("ITEM NR X");
}

I am kinda new to coding,I am looking for a method to loop this piece NTIMES. The nature of the site is that every time you additem.click() it creates a new texfield with id "item_rowX_txt" with X increasing by one each time.

I also have to fill these fields with the SendKeys command. Any tips please? I have just started learning java and working with selenium. ( tried to make the code as little as I could). I did some googling about looping N times but I dont know how to implement it for a class, and how to use the same variable (X) at those places you see in the code.

Ewhenn
  • 1
  • 3

1 Answers1

0

Before starting with selenium it is expected to have knowledge of any programming language, in this case JAVA. But you can try below solution:

//assuming that X is the number of times you want to execute the loop

public WebDriver Loopthisstuff (Webdriver driver, int X) {
//also assuming that the ID of first textbox is "item_row0_txt"
for(int i=0;i<X;i++)
{
    additem.click();
    WebElement answerX = driver.findElement(By.id("item_row"+i+"_txt"));
    answerX.sendKeys("ITEM NR "+i);
}
}
Aks.Soms
  • 137
  • 3
  • 13