硒中 ExpectedConditions.elementToBeSelected 和 elementSelectionStateToBe 有什么区别?如何使用它?你能举个例子吗?
待选元素
public static ExpectedCondition<java.lang.Boolean> elementToBeSelected(WebElement element)
元素选择状态ToBe
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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)