开发者

Register an already existing element tag in WatiN ElementFactory

I am not satisfied of the existing implementation of the SelectLi开发者_JAVA百科st 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

[ElementTag("select")]
public class ZwtSelectList : SelectList
{
    public ZwtSelectList(DomContainer container, ElementFinder finder) : base(container, finder) { }

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

However when I use

ElementFactory.RegisterElementType(typeof(ZwtSelectList));

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 ?


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

browser.Element<ZwtSelectList>(Find.Any).Select(...);

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜