While testing Application many times we need to select the values from combo box/dropdown. Here is the snippet shows how we can select values.
There are three ways to active it:-
1. selectByValue
2. selectByIndex
3. selectByVisibleText
Here is the snippet one can use to select item from dropdown box / combo box :-
WebElement select = driver.findElement(By.xpath("GiveXpathOfElement"));
Select s = new Select(select);
s.selectByValue(stringToSelect);
There are three ways to active it:-
1. selectByValue
2. selectByIndex
3. selectByVisibleText
Here is the snippet one can use to select item from dropdown box / combo box :-
WebElement select = driver.findElement(By.xpath("GiveXpathOfElement"));
Select s = new Select(select);
- if you want to select "ABC" from drop down then :
s.selectByValue(stringToSelect);
- if you want to select value from drop down which is at index 1 then :
s.selectByIndex(1);
s.selectByVisibleText(visiableValue);
- if you want to select visiable value from drop down which is at index 1 then :
s.selectByVisibleText(visiableValue);