0

In Selenium I am using UnSelectAll() on a normal select/Input element( Not multi select). What exception I can expect?

2
  • Not sure why you want to know about an exception? What is the scenario that you're testing? Commented Oct 6, 2016 at 9:39
  • Just try and write it down? Commented Oct 6, 2016 at 10:18

2 Answers 2

2

I am just putting code from select API of selenium.support.ui. The code is self explanatory

public void deselectAll() {
if (!isMultiple()) {
  throw new UnsupportedOperationException(
      "You may only deselect all options of a multi-select");
}

for (WebElement option : getOptions()) {
  setSelected(option, false);
}
}

Here isMultiple is defined in constructor of Select class as mentioned below

private final boolean isMulti;
public Select(WebElement element) {
.
.
.
.
String value = element.getAttribute("multiple");

// The atoms normalize the returned value, but check for "false"
isMulti = (value != null && !"false".equals(value));
}

public boolean isMultiple() {
   return isMulti;
}
-1

De-select all checkboxes -

WebElement parent = driver.findElement(By.xpath("<enter parent xpath>"));  
List<WebElement> children = parent.findElements(By.cssSelector("input:checked[type='checkbox']"));  
for (int i = 0; i < children.size(); i++) { children.get(i).click(); }

See this for more help

2
  • But I would like to know about the the excepted exception when I use deselect all ( actually deselectall is for multiselect item) But If my object is not a multi seelect item what exception i can expect?
    – SQA_LEARN
    Commented Oct 6, 2016 at 7:44
  • Why you are focusing on which exception will occur? Share scenario where you need help. Why looking desperately to fail and observe exception? Commented Oct 6, 2016 at 8:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.