如何使用Selenium的ExpectedCondition与Function.andThen?

时间:2017-12-03 21:12:22

标签: java selenium

我似乎没有弄清楚如何在ExpectedCondition的链中使用Selenium 3.7.1的Function.andThen。问题的最小化减少了以下的编译失败,我希望你不要考虑离题,因为它真的很棘手,而且没有任何例子或文档给我任何线索:

WebElement webElement0 = null;
Function<WebDriver, WebElement> function0 = ExpectedConditions.visibilityOf(webElement0);
Function<WebDriver, WebElement> function1 = ExpectedConditions.visibilityOf(webElement0).andThen(ExpectedConditions.elementToBeClickable(webElement0));

由于

而失败
richtercloud/selenium/and/then/NewMain.java:[25,97] method andThen in interface java.util.function.Function<T,R> cannot be applied to given types;
  required: java.util.function.Function<? super org.openqa.selenium.WebElement,? extends V>
  found: org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement>
  reason: cannot infer type-variable(s) V
    (argument mismatch; org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement> cannot be converted to java.util.function.Function<? super org.openqa.selenium.WebElement,? extends V>)

由于andThen的签名public <V> Function<T,V> andThen(Function<? super R,? extends V> after)添加ExpectedConditions.visibilityOf(webElement0).<WebElement>andThen(ExpectedConditions.elementToBeClickable(webElement0));应该会有所帮助,但由于

而失败
richtercloud/selenium/and/then/NewMain.java:[20,157] incompatible types: org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement> cannot be converted to java.util.function.Function<? super org.openqa.selenium.WebElement,? extends org.openqa.selenium.WebElement>

Function返回的所有其他andThen使用<? super WebElement, ? extends V>派生的内容时,为什么传递给Function的{​​{1}}希望拥有ExpectedConditions }作为第一个,结果作为秒参数。

我知道解决这个问题很容易。我想扩大我的技能,编写更易于理解的更短代码。

MCVE位于https://github.com/krichter722/selenium-and-then

0 个答案:

没有答案