for loop

Wait for at-least one element condition Selenium Webdriver 

There are a lots of situations in your automation scripts where you are waiting for an element to be verified on the page and you may get an error and the script still waits for the element to be loaded on the page rather than catching the error.
Here is the script that will do that and you can also stipulate the timeout for the condition.
The Script is coded in Java Selenium Webdriver and used the Java 5 for loop.

public void waitForOneElementPresent(int i, By... by) throws InterruptedException {
boolean found = false;
for (int second = 0; second <= i; second++) {
if (second >= i) {
break;
}
for (By singleBy : by) {
if (isElementPresent(singleBy)) {
found = true;
}
}
if (found) {
break;
}
Thread.sleep(1000);
}
}

By Pavandeep Puddupakkam on July 24, 2013 | Java, WebDriver | A comment?
Tags: , , ,