0

In the following Selenium Explicit wait , I see the method until returns something like

<V> V for the method until(com.google.common.base.Function<? super T,V> isTrue)

My doubt is how they are referencing it to a element of type WebElement?

WebElement element = b.until(ExpectedConditions.elementToBeClickable(By.id("Email")));
madth3
  • 7,275
  • 12
  • 50
  • 74
Fazy
  • 573
  • 1
  • 5
  • 16

2 Answers2

0

As you can check in the source, there is specified:

  • @param <V> The function's expected return type.
  • The method signature looks like : public <V> V until(Function<? super T, V> isTrue) {...}.

In conclusion, if you use ExpectedCondition parameter (this is most probably), the type its parameterized type. Look below for an example :

    try {
      (new WebDriverWait(webDriver, maxWaitTime)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
          return applyCondition(driver, locator);
        }
      });
      return true;
    }
    catch (TimeoutException ex) {
      return false;
    }

In this case, as you can see, the return type of the method until it is Boolean, which cames from parameterized type of ExpectedCondition : new ExpectedCondition<Boolean>

Ioan
  • 5,152
  • 3
  • 31
  • 50
0

Adding to the answer by loan, I think the question is more related to the working of generics then anything to do with webdriver. So, reading more about generics would help answer this question.

I am not sure if the below is the best explanation, but I will try to give it a shot :

When you call elementToBeClickable method it returns something like ExpectedCondition<WebElement>.

The until method returns V. V is a generic type placeholder. So what would V hold? V is same as the one in Function<? super T, V>

Your case : Function<? super T, V> = ExpectedCondition<WebElement>.

Look at the definition of ExpectedCondition then,

public interface ExpectedCondition<T> extends Function<WebDriver, T> {}

So in your case, it is ExpectedCondition<WebElement> which would mean Function<WebDriver, WebElement> So V is WebElement and hence it returns WebElement.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31