I would like to automate some repetitive task - say submitting some form more than once. I am stumbling on the page load issues, so I want you to ask you how do you do it. Say, I want to submit ten different entries to our form. so I can do something like this:
for (int i =0; i<10; i++){
String name = getNextName();
String surname = getNextSurname();
Webelement newUserButton = driver.findElement(By.id("newUser")));
newUserButton.click();
WebElement name = driver.findElement(By.id("name")));
name.sendKeys(name);
WebElement surname = driver.findElement(By.id("surname")));
surname.sendKeys(surname);
WebElement submit = driver.findElement(By.id("submit")));
submit.click();
}
But I found out that if my test environment is slowlier, the above loop can crash. I tried to add some Thread.sleep() to the code, but if I want so submit, say, 200 entries, it can be really long to do the script.
Is there any function which can wait only the time when the form is ready?
Webelement newUserButton = driver.findElement(By.id("newUser")));Or has it any sense to find elements each time?