Skip to main content

Posts

Showing posts from 2016

Working with Dropdown in Selenium Webdriver

WebDriver has a class called “ Select ” to interact with dropdown. Dropdown is an another WebElement like textbox, radio button, links etc. We use below methods frequently to interact with Dropdown using Select class. selectByIndex(int index) selectByValue(String value) selectByVisibleText(String text) getOptions() getFirstSelectedOption() Note: Select class can be found in org.openqa.selenium.support.ui  package Sample Dropdown: selectByIndex(int index): This method is used to select dropdown value by using index. This method accept integer as an argument. Index value always start from 0 (Zero). So if we want to select 2 nd value from dropdown we have to give index 1. Syntax: Select s = new Select(dropdown_WebElement); s.selectByIndex(1); Example: package selenium; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ...