Search code examples
c#htmlattributeselementwatin

How to Find.By a non-standard attribute with Watin?


I am using WatiN to test a site.
There is a checkbox that I need to verify whether it is checked or not, then act on it accordingly.
When the checkbox is checked, the HTML shows

<input type="checkbox" name="bean.enabledContentTypes" id="jive-form-choose-contenttypes-1" value="1" checked="CHECKED"/>

I see that I can use 'Find.ByID' or 'Find.ByName' and a bunch of other 'Find.By...' options, but there isn't one for 'Find.ByChecked'.

How can I Find by this apparently non-standard attribute?
My only idea (that I can't figure out) is to store the entire element, and then somehow check the Element as a string (not sure how to do this anyways) and see if Element.Contains("checked").
Seems like there's probably a more poignant way to do what I'm am after?


Solution

  • I found the answer:

    Find.By("attribute name", "attribute value")
    

    So for my purposes, it is:

    ie.TextField(Find.By("checked", "CHECKED")).Click();