Here is the rest of the code if it may help:
HtmlElementCollection theElementCollection;
HtmlDocument filters = webBrowser1.Document;
theElementCollection = webBrowser1.Document.GetElementsByTagName("input");
HtmlElementCollection pCollection = filters.GetElementById("filterSortBy").GetElementsByTagName("option");
List<HtmlElement> pList = new List<HtmlElement>();
foreach (HtmlElement pItem in pCollection) { pList.Add(pItem); }
HtmlElement pElement =
(HtmlElement)pList.Where(pOption => pOption.GetAttribute("value").Equals("price_low_high", StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault();
if (pElement.GetAttribute("value").Equals("price_low_high"))
{
pElement.SetAttribute("Selected", "price_low_high");
pElement.InvokeMember("click");
}
pList.Clear();
pCollection = filters.GetElementById("filterAvailability").GetElementsByTagName("option");
foreach (HtmlElement avItem in pCollection)
{
pList.Add(avItem);
}
pElement = pList.Where(pOption => pOption.GetAttribute("value").Equals("1")).SingleOrDefault();
if (pElement.GetAttribute("value").Equals("1"))
{
pElement.SetAttribute("Selected", "1");
pElement.InvokeMember("click");
}
Error point noted in comment on
pElement = pList.Where...
line.
Is it because I want the value to be equal to 1?
What I am trying to do is select the value option named 1 (in this website) from a drop down list
The variables are not declared in this statement because it was used in other areas of the code. I tried declaring new variables but still the same result
This is the website element inspection:
<select name="availability" id="filterAvailability">
<option value="" label="All" selected="selected">All</option>
<option value="1" label="In stock (793)">In stock (793)</option>
<option value="2" label="Pre-order (7)">Pre-order (7)</option>
</select>
I was thinking more about this problem and I think the problem is the Element list I made as it does not capture values that are numbers, only text. that is my assumption. Is there any list that accepts numbers that can be used for the webbrowser?
Thanks.