I'm new to both C# and Selenium WebDriver.
I know how to select/click on an option in a drop-down list, but I've a problem before that. Since the drop-down list is dynamically generated, I have to get all options/values from the list before running each case.
Is there anyone kindly tell me how to get all values/options from a drop-down list. I'm using IE and I didn't find any class which supports method to get values/options in Selenium.IE namespace for C#.
My example: A list contains several time zones:
<TD>
<select name = "time_zone">
<option value "-09:00"><script>timezone.Alaska</script></option>
<option value "+00:00"><script>timezone.England</script></option>
<option value "+02:00"><script>timezone.Greece</script></option>
<option value "+05:30"><script>timezone.India</script></option>
</select>
<TD>
This is a drop-down list in an IE page and how to get the dynamically generated time zone list?
My code:
IWebElement elem = driver.FindElement(By.XPath("//select[@name='time_zone']"));
List<IWebElement> options = elem.FindElements(By.TagName("option"));
C# just pops an Error: Cannot implicitly covert type 'OpenQA.Selenium.IWebElement' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?).
thanks.
It seems to be a cast exception. Can you try converting your result to a list i.e.
elem.findElements(xx).toList
?