How to flegar a checkbox via webbrowser?

I am trying to mark a checkbox via webbrowser, but I am not being able to mark.

HtmlElementCollection theElementCollection = default(HtmlElementCollection);
theElementCollection = doc.GetElementsByTagName("div");
foreach (HtmlElement curElement in theElementCollection)
{
    if (curElement.GetAttribute("className").ToString() == "checkbox")
    {
        foreach (var item in curElement.All)
        {
            if (((HtmlElement)item).InnerText == null)
                continue;

            if (((HtmlElement)item).InnerText.Contains(" Windows 10") || ((HtmlElement)item).InnerText.Contains(" Windows XP")
                || ((HtmlElement)item).InnerText.Contains(" MS-DOS"))
            {
                ((HtmlElement)item).SetAttribute("checked", "true");
            }
        }
    }

    if (curElement.GetAttribute("className").ToString() == "radio")
    {
        foreach (var item in curElement.All)
        {
            if (((HtmlElement)item).InnerText == null)
                continue;

            if (((HtmlElement)item).InnerText.Contains("Masculino"))
            {
                ((HtmlElement)item).SetAttribute("checked", "true");
            }
        }
    }
}

insert the description of the image here

When I check the html of the page it is setting the label checked="true

insert the description of the image here

Author: Marco Souza, 2017-10-16

1 answers

As requested the solution looked like this.

if (curElement.GetAttribute("className").ToString() == "checkbox")
    {
        foreach (var item in curElement.All)
        {
            if (((HtmlElement)item).InnerText == null)
                continue;

            if (((HtmlElement)item).InnerText.Contains(" Windows 10") || ((HtmlElement)item).InnerText.Contains(" Windows XP")
                || ((HtmlElement)item).InnerText.Contains(" MS-DOS"))
            {
                ((HtmlElement)item).FirstChild.SetAttribute("checked", "true");
            }
        }
    }

Just use FirstChild.

 0
Author: Marco Souza, 2017-10-17 12:52:59