Wait for multiple elements presents


import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class waitForMultipleElements {
WebDriver driver = new FirefoxDriver();

public boolean isElementPresent(By by) {
try {
driver.findElements(by);
return true;
} catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
}
public void waitForMultipleElementsPresents(By[] by, int time) throws InterruptedException {
int length = by.length;
for (int i = 0; i <= (length - 1); i++) {
for (int j = 0; j <= time; j++) {
if (j >= time) {
break;
}
if (isElementPresent(by[i])) {
break;
}
}
}
}

@Test
public void myTest() throws IOException, InterruptedException {
driver.get("");

By[] elements = new By[2];
elements[0] = By.id("id");
elements[1] = By.xpath("xpath");
waitForMultipleElementsPresents(elements, 10);

}

}

No images available.