1

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?

7
  • What do you mean by "wait only the time when the form is ready", what defines ready? Commented Apr 10, 2012 at 15:07
  • submit.click() will wait for the page to finish loading before resuming so there is probably some other subtlety that is causing the problem. What exactly is the error when the loop crashes? Commented Apr 10, 2012 at 15:41
  • Not a solution, but I think you can carry out from your loop all elements definings like Webelement newUserButton = driver.findElement(By.id("newUser"))); Or has it any sense to find elements each time? Commented Apr 10, 2012 at 15:59
  • @Nix - Form ready means that after click all fields are loaded. Commented Apr 10, 2012 at 16:56
  • @prestomanifesto - the submit.click(); does not do that - verified :) Commented Apr 10, 2012 at 16:56

2 Answers 2

2

Sounds like you need to add an explicit wait - see the Webdriver page Advanced Usage - Explicit and Implicit Waits

With the explicit waits, you can tell webdriver to wait until the form is in the ready state - typically a certain field is visible or reset (depends on what happens to your form when you click submit).

Sign up to request clarification or add additional context in comments.

2 Comments

sounds like what I need. Will research it tomorrow and tell you how it went
YES! Exactly what I needed. And it was before my eyes the whole time :)
1

If you are using Selenium 2.0 you can make the WebDriver to wait until some action takes place by creating a WebDrivewWait object in you code. You can check out this link for more info - http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.