我似乎没有弄清楚如何在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
}作为第一个,结果作为秒参数。
我知道解决这个问题很容易。我想扩大我的技能,编写更易于理解的更短代码。