Along side the web elements, the drop down commands are the final piece necessary to create our full featured tests.
The following are just a few of the available methods for testing drop down lists. Just as web elements, a css selector by id or xpath can be used. to find the element.
Command | C# | Description |
SelectByText | IWebelement el = driver.FindElement(By.xpath(“t”)); SelectElement sl= new SelectElement(el); select.SelectByText(“”); | Select an option. |
SelectByValue | IWebelement el= driver.FindElement(By.xpath(“”)); SelectElement sl = new SelectElement(el); select.SelectByValue(“”); | Select an option |
Select List Option Commands
Select List Unit Test
On the main page, we add two drop down lists that contain the numbers 1 and 2, the selected value will also be 1 or 2. When the two drop down values are selected, a javascript element runs that adds the two values together and stores it in a label.
First modify index to satisfy the above problem statement. The drop downs will be labeled ‘one’ and ‘two’ and the label will have id ‘result’.

Next develop the test to select the two values and assert the result.

This test retrieves the down downs and sets their respective values. The label element is then retrieved and compared with an assert statement.
Download the source here.