I'm trying to do a simple task of trying to select a value in a dropdown by using the text shown. The scenario is as below.
My HTML looks like.
<div id="TestContainer" class="col-md-4">
<select onchange="Test()">
<option>Test1</option>
<option>Test2</option>
<option>Test3</option>
<option>Test4</option>
</select>
</div>
By using selenium i want to use the second item in the dropdown that is test2. C# code which i have written for the same is.
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
string localURL = "http://localhost:82/";
using (IWebDriver driver = new FirefoxDriver(service))
{
driver.Navigate().GoToUrl(localURL);
var div = driver.FindElement(By.Id("TestContainer"));
div.Click();
IWebElement dropDownListBox = div.FindElement(By.TagName("select"));
SelectElement demoSelect = new SelectElement(dropDownListBox);
demoSelect.SelectByText("Test2");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
}
Apart from the above i have even tried iterating the options one by one and selecting the appropriate item like below also to no avail.
if (option.Text.Equals("Test2"))
{
option.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
break;
}
In both the above cases, The code doesn't break and no exception is thrown but the value will not be selected and nothing seems to be happening.
The version of selenium i'm using is as below.
<package id="Selenium.Support" version="2.53.1" targetFramework="net452" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net452" />
<package id="WebDriver.GeckoDriver"version="0.9.0"targetFramework="net452" />
Also i'm using the latest version of firefox (48.0)
Has anyone faced this issues before? It would be great if you could point me in the right direction.