How to flex a checkbox via webbrowser?

1

I'm trying to mark a checkbox via webbrowser, but I can not dial.

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");
            }
        }
    }
}

WhenIcheckthehtmlofthepageheissettinglabelchecked="true

    
asked by anonymous 16.10.2017 / 18:33

1 answer

0

As requested the solution went 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 .

    
17.10.2017 / 14:52