Tuesday, 28 April 2015

Working with "Multi Select list box"

package WebdriverDemo2;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class MultiSelectDemo {

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();

driver.get("http://www.plus2net.com/html_tutorial/html_frmddl.php");

WebElement wele = driver.findElement(By.xpath("//select[@name='ddl' and @multiple='']"));

Select slt = new Select(wele);

boolean flag = slt.isMultiple();
List<WebElement> lst = slt.getOptions();

int count=lst.size();

if(flag)
{
for(int i=0;i<count;i++)
{
slt.selectByIndex(i);
}
}

}

}

No comments:

Post a Comment