Question

I'm trying to get checkbox's checked Attribute.I try using GeckoHtmlElement's
GetAttribute() function but it always returns null value for checked Attribute.

I try this:

Gecko.GeckoElementCollection z = Browser.Document.GetElementsByName("productBox[]");
foreach (Gecko.GeckoNode o in z)
{
   if (o.NodeType == NodeType.Element)
   {
      GeckoHtmlElement asd = (GeckoHtmlElement)o;
      string aa =asd.GetAttribute("checked");
      if (aa != null && aa == "True")
          liaaa.Add(o);
   }
}

checkBoxes's Html:

<input name="productBox[]" value="10914" class="noborder" type="checkbox">

I try this but still not working. This returns a Null Gecko Node :

string aa =asd.Attributes["checked"];

UPDATE:
I completed my work but my way is uggly ,dirty and less usable.In browsers DomMouseUp event :

GeckoElement active = (GeckoElement)browser.Document.ActiveElement;
if (active.Attributes["name"].TextContent == "productBox[]")
{
   if (getHtmlelement(active).Parent.GetAttribute("style") == null ||
       getHtmlelement(active).GetAttribute("style") == "")
   {
      getHtmlelement(active).SetAttribute("style", "MyCheck");
      liaaa.Add(active);
   }
   else
   {
      getHtmlelement(active).SetAttribute("style", "");
      liaaa.Remove(active);
   }
}

It's working for now because all checkboxes are not checked by default when page loads.But a better way can help a lot.

Thanks

Was it helpful?

Solution 2

Casting to a GeckoInputElement will give you access to the Checked property:

if (o.NodeType == NodeType.Element && o is GeckoInputElement)
{
      GeckoInputElement asd = (GeckoInputElement)o;
      if (asd.Checked)
        ....
}

OTHER TIPS

string aa =asd.Attributes["checked"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top