Showing posts with label drop down with web driver. Show all posts
Showing posts with label drop down with web driver. Show all posts

Handling drop-down with Selenium

Selenium Select class is used to perform actions on drop-down:
Different functions provided by Select class:


selectByVisibleText()/deselectByVisibleText()
selects or deselects an option by its visible text from drop down
selectByValue()/deselectByValue()
selects or deselects an option by the value displayed for "value" attribute
selectByIndex()/deselectByIndex()
selects or deselects an option by its index
isMultiple()
returns TRUE if the drop-down allows multiple selection at a time and return FALSE if not allowed
deselectAll()
deselects all selected options



Sample Code:
WebElement dropdown = driver.findElement(By.name("dropdown"));
Select select = new Select(dropdown);

// Here we will perform the multiselect operation in the dropdown.
select.selectByVisibleText("John");

Select from drop down using Webdriver

Select oSelection = new Select(driver.findElement(By.id("sampleID")));

    oSelection.selectByIndex(index)

    oSelection.selectByIndex(index)

    // Or

    oSelection.selectByVisibleText(text)

    oSelection.selectByVisibleText(text)

    // Or

    oSelection.selectByValue(value)

    oSelection.selectByValue(value)