gpt4 book ai didi

selenium - Selenium 中 ExpectedConditions.elementToBeSelected 和 elementSelectionStateToBe 之间的区别

转载 作者:行者123 更新时间:2023-12-03 05:54:02 25 4
gpt4 key购买 nike

selenium 中的 ExpectedConditions.elementToBeSelected 和 elementSelectionStateToBe 有什么区别?如何使用它?能举个例子吗?

最佳答案

要选择的元素

public static ExpectedCondition<java.lang.Boolean> elementToBeSelected(WebElement element)

ElementSelectionStateToBe

public static ExpectedCondition<java.lang.Boolean> elementSelectionStateToBe(WebElement element, boolean selected)

正如您从方法签名中看到的,elementSelectionStateToBe 接收 boolean 作为参数。您可以通过传递参数来检查元素是否被选中,而在 elementToBeSelected 中则需要捕获异常来检查元素是否未被选中。

检查元素是否被选中

// waits for the element to be selected
wait.until(ExpectedCondition.elementSelectionStateToBe(element, true));

// waits for the element to be selected
wait.until(ExpectedCondition.elementToBeSelected(element));

检查元素是否未被选择

// waits for the element **not** to be selected
wait.until(ExpectedCondition.elementSelectionStateToBe(element, false));

try {
// waits for the element to be selected
wait.until(ExpectedCondition.elementToBeSelected(element));
}
catch (TimeOutException)
{
// the element is not selected
}

关于selenium - Selenium 中 ExpectedConditions.elementToBeSelected 和 elementSelectionStateToBe 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35208638/

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