Take the 2-minute tour ×

I am not satisfied of the existing implementation of the SelectList class in WatiN, especially the Select method, or SelectByValue method which doesn't trigger the onchange event.

I want to create my own class ZwtSelectList which inherits from SelectList and override the problematic methods

public class ZwtSelectList : SelectList
    public ZwtSelectList(DomContainer container, ElementFinder finder) : base(container, finder) { }

    public override void Select(string text)
        DomContainer.Eval(string.Format("$('#{0}').change()", Id));

However when I use


I get

System.InvalidOperationException: Types SelectList and ZwtSelectList have both registered element tag 'SELECT'

Is there a way to unregister an already registered tag ? Or a way to override the already registered tag ?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Currently registering your own element as a replacement for a native WatiN element isn't supported. But you can use:


It shouldn't be to hard to change the ElementFactory implementation to allow re-registering your custom element for an already registered element as long as the custom element inherits from the original element registered for that tag or tags (just like you did with your SelectList).

I would advise to get the latest code from the SVN repository on SourceForge cause I have fixed issues with the example code above since WatiN RC1.

share|improve this answer
thanks for you answer. I am currently using WatiN- which is the current RC1. I will try to wrote a patch for what you suggest. –  Baptiste Pernet Dec 30 '10 at 9:41
your solution browser.Element<ZwtSelectList>(Find.Any).Select(...); doesn't exist. Did you mean browser.ElementOfType<ZwtSelectList>(Find.Any).Select(...); ? If I do that, then it tries the register the unregistered Type ZwtSelectLIst and I get the same exception –  Baptiste Pernet Dec 30 '10 at 10:00
Hi, I sent you a message over sourceforge so that you can get the patch that allow to register inherited type. Thanks for your time if you could have a look. –  Baptiste Pernet Dec 30 '10 at 10:24
Hi, I don't know if you get my mail, but I told you that you can get the path here: sp4ce.net/watin/register_inherited.patch I woul be happy if this change could be include in a new RC... –  Baptiste Pernet Dec 31 '10 at 14:07
add comment

Note that WatiN does fire an event called "onchange" which is not the same as the "change" event. The poster's code does fire the "change" event for the element, but WatiN's implementation of Select() and its variants don't work. The reason being that WatiN 2.0's code is buggy and isn't firing the "change" event but rather the "onchange" event, which presumably no one hooks their event handlers to.

If that bug happened to be fixed, one could use Select() via the WatiN core and it presumably would work correctly.

share|improve this answer
add comment

Your Answer


