Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
{
            string entry = Titleentry.Text;

            HtmlElementCollection theElementCollection;
            HtmlDocument filters = webBrowser1.Document;

            theElementCollection = webBrowser1.Document.GetElementsByTagName("input");

            foreach (HtmlElement curElement in theElementCollection)
            {
                if ((curElement.GetAttribute("id").ToString() == "searchTitle"))
                {
                    curElement.SetAttribute("value", entry);
                }
            }
filters.GetElementById("filterSortBy").GetAttribute("option").Select("price_low_high");


            //foreach (HtmlElement curElement in option)
            //{
            //    if option = ("price_low_high");
            //}

            theElementCollection = webBrowser1.Document.GetElementsByTagName("button");

            foreach (HtmlElement curElement in theElementCollection)
            {
                if (curElement.GetAttribute("id").Equals("searchSubmit"))
                {
                    curElement.InvokeMember("click");
                }
            }


the marked statement gives me the following message:

Error 1 The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

what I am trying to do is get elements by ID from a website since if I try elements by tag name it is choosing the incorrect element

I tried using html collections but it says cannot implicitly convert html elements to html collections

Update:

The sample of the HTML code:

<select name="searchSortBy" id="filterSortBy"> 
  <option value="popularity" label="Most popular" selected="selected">Most popular</option> 
  <option value="price_low_high" label="Price, low to high">Price, low to high</option> 
  <option value="price_high_low" label="Price, high to low">Price, high to low</option> 
</select>


thanks
Posted
Updated 24-Oct-13 4:01am
v4
Comments
Timberbird 24-Oct-13 8:21am    
Looks like the problem is in this part: .Select("price_low_high"). GetAttribute("option") returns a string containg the value of the "option" attribute, and then you try to select something from that string. I must admit I don't understand what you are trying to achieve with this method call, but anyway String.Select() has different syntax.
slayasty 24-Oct-13 8:42am    
what i am trying to do is selecting the option: setting price lowest first from the filters of the website. maybe i need to use different html elements or something?
Timberbird 24-Oct-13 9:27am    
So let me guess: you have a structure like the following:
<select id="filterSortBy">
<option value="val1"> Filter type 1 </option>
<option value="val2"> Filter type 2 </option>
<option value="price_low_high"> Sort by price ascending </option>

</select>
,
and you want to select an "option" element that has value "price_low_high" (i.e. the third one), right? Correct me if I'm wrong. It would be good to add sample HTML fragment you're trying to parse to the original question.
slayasty 24-Oct-13 9:51am    
yep thats exactly what i want to do. here is the html for the filter sort:

<select name="searchSortBy" id="filterSortBy">
<option value="popularity" label="Most popular" selected="selected">Most popular</option>
<option value="price_low_high" label="Price, low to high">Price, low to high</option>
<option value="price_high_low" label="Price, high to low">Price, high to low</option>
</select>

thanks
Timberbird 24-Oct-13 10:08am    
You could try the following:

HtmlElement pElement = (HtmlElement) filters.GetElementById("filterSortBy").GetElementsByTagName("option").Where(pOption => pOption.GetAttribute("value").Equals("price_low_high", StringComparison.InvariantCultureIgnoreCase) ).FirstOrDefault();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900