Reputation: 179
In my application , when I click on any element a waiting image is displayed. I can create an explict wait for waiting that image to get disappeared but I have to write that after every click code. I want to create a implicit wait. So that I can avoid writing that code every time.
Please help. Thanks in advance !!
Upvotes: 1
Views: 1119
Reputation: 474191
Just apply the "Extract method" refactoring method. Create a separate reusable function/method that aside from clicking an element would wait for an invisibility of the waiting image.
Here is a simple example (should be improved definitely):
public void clickAndWait(WebDriver driver, By by) {
driver.findElement(by).click();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("waiting_image")));
}
Upvotes: 2
Reputation: 16201
There is a significant difference between implicit and explicit wait. For finding element explicit wait is always best option. I would suggest write a custom finElement()
method which has the explicit wait baked in so that you do not need to write the explicit wait every time. You do no want to use implicit wait everywhere since if the element is not there it will give performance issue in your test execution.
Upvotes: 2