This is driving me crazy and I have tried using By.Id or By.Xpath
but none works and here is my Select Method
trying to select the text from Dropdownlist
//Test code
SelectMyText(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_ddlCategory']"), "Employee");
//method:
public void SelectMyText(By locator, string valueToBeSelected)
{
var options = GetElementId(locator).FindElements(By.TagName("option"));
foreach (var option in options)
{
if (valueToBeSelected == option.Text)
{
option.Click();
return;
}
}
}
public IWebElement GetElementId(By locator)
{
return Driver.FindElement(locator);
}
Here is the error getting:
threw exception:
System.NotImplementedException: Element is no longer valid
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.get_Text()
Here are the screen shots of this error: