#286 WatiN removes javascript behaviours when typing on inputs

open
nobody
None
5
2012-09-15
2012-05-25
Anonymous
No

Hi,

I have a web application where I am using a jQuery plugin named inputmask ( https://github.com/RobinHerbots/jquery.inputmask ). I works great on IE, but when I run a test WatiN clears the mask and write just a raw value.

I have upload a sample project that contains a page named MaskAndWatiNProblem.html with an INPUT and a inputmask. When you run the console application, it uses WatiN to test it. But when WatiN type on the input, the mask disappears, so it cannot be tested properly.

You can download the project from here vtortola.net/files/jQueryInputMaskAndWatiN.zip

The input has the mask \"dd/mm/yyyy\", so when you introduce \"01022000\" it should be formatted to \"01/02/2000\", and when you read the value from the input should be also \"01/02/2000\".

Any idea about why WatiN disables this plugin?

Thanks.

Discussion


  • Anonymous
    2012-06-08

    I did some further testing and in the keydown keypress event the args e.which || e.charCode || e.keyCode always return 0, ... I also tried with some patching in de watin code.

    in IEFireEventHandler

    private string CreateJavaScriptFireEventCode(NameValueCollection eventObjectProperties, string eventName)
    {
    var scriptCode = new StringBuilder();
    var window = _ieElement.ParentWindow;
    if (IE.GetMajorIEVersion() > 8 && eventName.ToLower().Contains("key"))
    {
    scriptCode.Append("var newEvt = document.createEvent('KeyboardEvent');");

                //init keyboardevent
                scriptCode.AppendFormat("newEvt.initKeyboardEvent('{0}',true, true, null, false, false, false, false, null, {1});", eventName.ToLower().Replace("on", ""), eventObjectProperties.GetValues(0)[0]);
    
                var reference = _ieElement.GetJavaScriptElementReference();
                scriptCode.AppendFormat("{0}.dispatchEvent(newEvt);", reference);
            }
            else
            {
                scriptCode.Append("var newEvt = document.createEventObject();");
                CreateJavaScriptEventObject(scriptCode, eventObjectProperties);
    
                var reference = _ieElement.GetJavaScriptElementReference();
                scriptCode.Append(string.Format("{0}.fireEvent('{1}', newEvt);", reference, eventName));
            }
    
            return scriptCode.ToString();
        }