What is the Difference between ExpectedConditions.elementToBeSelected and elementSelectionStateToBe in selenium? How to use it? Can you give any example?
ElementToBeSelected
public static ExpectedCondition<java.lang.Boolean> elementToBeSelected(WebElement element)
ElementSelectionStateToBe
public static ExpectedCondition<java.lang.Boolean> elementSelectionStateToBe(WebElement element, boolean selected)
As you can see from the methods signature elementSelectionStateToBe receives boolean as parameter. You can use this to check if the element is selected or not by passing parameter, while you need to catch an exception to check if the element isn't selected in elementToBeSelected.
To check if element is selected
// 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));
To check if element is not selected
// 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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With