I'm not able to select options in a drop down list. I think I need to have .Select
or SelectElement
, but there is no such option.
Sample code:
IWebDriver ffbrowser = new FirefoxDriver();
ffbrowser.Navigate().GoToUrl("http://www.amazon.com/");
ffbrowser.Manage().Window.Maximize();
Thread.Sleep(500);
IWebElement ddl = ffbrowser.FindElement(By.Name("url"));
int numofitems = ddl.FindElements(By.TagName("option")).Count;
for (int i = 1; i < numofitems; i++)
{
ffbrowser.select("TagName = option", "index = i");
}
The "select" in "ffbrowser.select" is reported as an error:
Error 1 'OpenQA.Selenium.IWebDriver' does not contain a definition for 'select' and no extension method 'select' accepting a first argument of type 'OpenQA.Selenium.IWebDriver' could be found (are you missing a using directive or an assembly reference?)
My project references include Selenium.WebDriverBackedSelenium
, Thoughtworks.Selenium.Core
, WebDriver
, WebDriver.Support
and I have
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
Initially you have to import the Select class and afterward you have to make the case of Select class. After making the case of Select class, you can perform select strategies on that occasion to choose the choices from dropdown list. Step-by-step approach: Import webdriver from selenium module.
To handle drop down and multi select list using Selenium WebDriver, we need to use Select class. The Select class is a Webdriver class which provides the implementation of the HTML SELECT tag. It exposes several “Select By” and “Deselect By” type methods.
The 'Select' class in Selenium WebDriver is used for selecting and deselecting option in a dropdown. The objects of Select type can be initialized by passing the dropdown webElement as parameter to its constructor.
Depending what version of Selenium WebDriver you are using you can use the SelectElement
class, which will be included in OpenQA.Selenium.Support.UI
.
For example:
SelectElement selector = new SelectElement(element);
selector.SelectByIndex(1);
Where the element is your drop down box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With