Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium WebDriver Java:将表达式转换为Lambda_Java_Selenium_Selenium Webdriver_Lambda - Fatal编程技术网

Selenium WebDriver Java:将表达式转换为Lambda

Selenium WebDriver Java:将表达式转换为Lambda,java,selenium,selenium-webdriver,lambda,Java,Selenium,Selenium Webdriver,Lambda,我正在寻找一种使用lambda编写此块的方法: public void waitUntilElemIsDisabled(WebElement element) { try { wait.until(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) {

我正在寻找一种使用lambda编写此块的方法:

public void waitUntilElemIsDisabled(WebElement element) {
        try {
            wait.until(new Function<WebDriver, Boolean>() {
                @Override
                public Boolean apply(WebDriver driver) {
                    return !element.isEnabled();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.toString());
        }
    }
如果有帮助,下面是我如何初始化
等待

wait = new FluentWait<>(webDriver).withTimeout(impTimeout, s).pollingEvery(pollingMsInt, ms)
                    .ignoring(NoSuchElementException.class);
wait=new FluentWait(webDriver)。带超时(impTimeout,s)。轮询每一个(pollingMsInt,ms)
.忽略(NoSuchElementException.class);
我在使用lambda方面相当新,目前正在遵循指南,但我找不到与我正在使用的模式匹配的模式


提前谢谢。

设法解决了这个问题

解决方案:

private Function<WebDriver, Boolean> webElemBooleanFunction(boolean condition) {
    return x -> condition;
}

谢谢你的提示

看起来您可能正在使用不推荐的
until()
方法。看看这个,我经常使用IDE的重构功能来代替用我的大脑来解决这些问题。在IntelliJ中,我会单击lambda,使用Refactor/Extract-to-Value,根据需要更正类型参数,然后使用Refactor/Inline将值重新集成到原始表达式中。通常,它会自动添加任何需要的强制转换或显式类型参数。
private Function<WebDriver, Boolean> webElemBooleanFunction(boolean condition) {
    return x -> condition;
}
public void waitUntilFieldIsPopulated(WebElement element) {
    try {
        wait.until(webElemBooleanFunction(getElementValue(element).length() > 0));
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.toString());
    }
}