Now you lot tin easily select or deselect whatever specific alternative from choose box or driblet down equally described inward my before POST 1, POST 2 in addition to POST 3. All these 3 posts volition clit you lot unlike alternative ways of selecting options from listing box or driblet down. Now permit me guide keep you lot i pace ahead to clit you lot the live on of deselectAll() in addition to isMultiple() methods inward selenium webdriver.
deselectAll() Method
deselectAll() method is useful to take pick from all selected options of choose box. It volition industrial plant amongst multiple choose box when you lot postulate to take all selections. Syntax for deselectAll() method is equally bellow.
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.deselectAll();
isMultiple() Method
isMultiple() method is useful to verify if targeted choose box is multiple choose box or non agency nosotros tin choose multiple options from that choose box or not. It volition provide boolean (true or false) value. We tin live on it amongst if status before working amongst choose box. Syntax is equally bellow.
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); boolean value = listbox.isMultiple(); System.out.print(value);
Bellow given instance volition demo you lot live on of isMultiple() in addition to deselectAll() methods really clearly inward selenium webdriver.
@Test populace void examine () throws InterruptedException { Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); //To verify that specific choose box supports multiple choose or not. if(listbox.isMultiple()) { System.out.print("Multiple selections is supported"); listbox.selectByVisibleText("USA"); listbox.selectByValue("Russia"); listbox.selectByIndex(5); Thread.sleep(3000); //To deselect all selected options. listbox.deselectAll(); Thread.sleep(2000); } else { System.out.print("Not supported multiple selections"); } }
In higher upward example, if status volition banking concern gibe that listbox is multiple choose box or not? Used listbox.deselectAll(); to take all selected options.
You tin VIEW MORE SELENIUM WEBDRIVER BASIC COMMANDS.