gpt4 book ai didi

java - 如何用 lambda 表达式替换 WebDriverWait()?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:36 24 4
gpt4 key购买 nike

我想知道如何用 lambda 替换流行的 WebDriverWait

它用于显式等待某个事件。

代码片段:

(new WebDriverWait(Driver.driver.get(), 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.findElement(By.id("DataTables_Table_0_processing")).isDisplayed();
}
});

或者:

(new WebDriverWait(Driver.driver.get(), 10))
.until(ExpectedConditions
.invisibilityOfElementLocated(By.id("DataTables_Table_0_processing")));

如何用lambda表达式代替?

最佳答案

(new WebDriverWait(Driver.driver.get(), 10))
.until(d -> d.findElement(By.id("DataTables_Table_0_processing")).isDisplayed());

我认为 lambda 不会改进第二种情况,因为已经有一种提供足够清晰度的便捷方法。

关于java - 如何用 lambda 表达式替换 WebDriverWait()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32789418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com