Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
Get HTML CheckBox state in a WebBrowser control

How can I get the state of a HTML CheckBox in a WebBrowser control?

I have the following variable in my class:

private WebBrowser quickStartGuideContentWebBrowser = new WebBrowser();

I also have the following constant in my class:

private const string doNotShowAgainCheckBoxElementId = "do-not-show-again-checkbox";

I also have the following function in my class;

private HtmlElement GetDoNotShowAgainCheckBox()
{
    HtmlDocument document = this.quickStartGuideContentWebBrowser.Document;
    if (document == null)
    {
        Debug.WriteLine("GetDoNotShowAgainCheckBox error: (document == null).");
        return null;
    }
    return document.GetElementById(doNotShowAgainCheckBoxElementId);
}

I am trying to implement a IsDoNotShowAgainCheckBoxChecked method as follows:

private bool IsDoNotShowAgainCheckBoxChecked()
{
    HtmlElement checkboxElement = GetDoNotShowAgainCheckBox();
    if (checkboxElement == null)
    {
        Debug.WriteLine("IsDoNotShowAgainCheckBoxChecked error: (checkboxElement == null).");
        return false;
    }
    // What magical incantation do I put here 
    // to retrieve the checked state of checkboxElement as a bool?
    return false;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You just need to get the checked Attribute using the HtmlElement.GetAttribute() method.
It will be "True" or "False" (string), based on the state of the CheckBox.

if (quickStartGuideContentWebBrowser.ReadyState != WebBrowserReadyState.Complete) return;

var chkBoxElm = quickStartGuideContentWebBrowser.Document.
    GetElementById(doNotShowAgainCheckBoxElementId);

if (chkBoxElm != null) {
    var state = chkBoxElm.GetAttribute("checked");
    if (state = "True") {
        Console.WriteLine("The CheckBox state is 'checked'");
    }
}

The GetAttribute() method can of course be used to retrieve any other Attribute of an HtmlElement, e.g., its className.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda