2012-11-08 44 views
0

在下面的硒顯式的等待,我看到until返回類似硒WebDriverWaits

<V> V的方法until(com.google.common.base.Function<? super T,V> isTrue)

我懷疑是他們如何引用它來WebElement類型的元素的方法是什麼?

WebElement element = b.until(ExpectedConditions.elementToBeClickable(By.id("Email"))); 
+1

你究竟想知道什麼?這個問題不是很清楚。 –

回答

0

正如你可以在源頭上,有規定:

  • @param <V> The function's expected return type.
  • 方法簽名是這樣的:public <V> V until(Function<? super T, V> isTrue) {...}

總之,如果使用ExpectedCondition參數(這很可能是),那麼它的類型就是它的參數化類型。看看下面的例子:

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; 
    } 

在這種情況下,你可以看到,該方法的返回類型until這是Boolean,從參數化類型的ExpectedCondition卡梅斯:new ExpectedCondition<Boolean>

0

添加到答案通過貸款,我認爲這個問題更多地涉及到泛型的工作,然後與webdriver有什麼關係。所以,閱讀更多關於generics將有助於回答這個問題。

我不知道,如果下面的就是最好的解釋,但我會盡量給它一個鏡頭:

當你調用它返回像ExpectedCondition<WebElement> elementToBeClickable方法。

的直到方法返回V. V是一個通用型佔位符。那麼V會持有什麼? V與Function<? super T, V>相同

您的情況:Function<? super T, V> = ExpectedCondition<WebElement>

看ExpectedCondition的定義,然後,

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

所以你的情況,這是ExpectedCondition<WebElement>這意味着Function<WebDriver, WebElement> 所以V是WebElement,因此它返回WebElement。