2016-02-04 268 views

回答

1

ElementToBeSelected

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 
} 
+0

只是为了一点点加入到这样的回答: ExpectedCondition.elementToBeSelected(元)实际调用ExpectedCondition。 elementSelectionStateToBe(element,true): 'public static ExpectedCondition elementToBeSelected(final WebElement element){ return elementSelectio nStateToBe(element,true); }'[src](https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java) – NotInventedHere