Honestly, with a good implementation of test automation framework, you don't need implicitWait
. You should always explicitly wait for the conditions.
The implicit wait might cause your tests to run slower. Automated Test Suite should always run as fast as possible to provide feedback to the team.
BUT, if you insist on using it, you can simply create some kind of method/class where you turn off implicit waits, perform explicit wait, and restore implicit wait value.
Something like this:
public class Wait {
private static final int IMPLICIT_WAIT_TIME = 10; //store your default implicit wait here or use .properties file
private WebDriver driver;
private int timeout = 10;
private List<Class<? extends Throwable>> exceptions = new ArrayList<>();
public Wait(WebDriver driver) {
this.driver = driver;
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //turn off implicit wait
}
public Wait setTimeout(int seconds) {
this.timeout = seconds;
return this;
}
@SafeVarargs
public final Wait ignoring(Class<? extends Throwable>... exceptions) {
this.exceptions.addAll(Arrays.asList(exceptions));
return this;
}
public void until(ExpectedCondition... expectedConditions) {
WebDriverWait wait = new WebDriverWait(driver, timeout);
if (exceptions.size() > 0) {
wait.ignoreAll(exceptions);
}
wait.until(ExpectedConditions.and(expectedConditions));
driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME, TimeUnit.SECONDS); //restore implicit wait
}
}