Need Help in creating a function to wait

public void testLogin_ExplicitWait() {
WebDriverWait wait = new WebDriverWait(driver, 10);



Hi I’m using this explicit wait to do my task, I want to create a function to use this command with that function

Can anyone help, thanks in advance

The is not much to do… just copy it to an external function and call it with the right params… basically the only param should be of ExpectedCondition class.

  • use java generics.


public <T> T myWaitFunction(ExpectedCondition<T> condition) {
return wait.until(condition);

in your test method run:

and if you only use presenceOfElementLocated by the way, you should not. you should use elementToBeClickable expected condition before clicking an element. but, if you decide to use only presenceOfElementLocated you can do like so:

public <T> T myWaitForPresenceFunction(WebElement element) {
return wait.until(presenceOfElementLocated(element));

and then from your test method just call:

For me, I just create a util with all the common actions (click, getText etc…)
then just call clickElement(loginButton) for example.