How to select all the options present in Multi-Select List box using Selenium WebDriver

04 April, 2014
We can use the below code to select all the options present in multi-select list box.

Read here about how to handle the List Box (Drop Down List and Multi-Select List).

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MultiSelect {

	public static void main(String[] args) throws InterruptedException {
		WebDriver driver = new FirefoxDriver();
		WebElement listBox = driver.findElement("countrySelect"));
		Select select = new Select(listBox);
		int size= select.getOptions().size();
		System.out.println("Number of Options: " +size);
		for (int i = 0; i < size; i++) {

No comments:

Post a Comment