3

I am writing an automated test to test a sign up page. Each of the textbox on this page is validated on blur event. Sign up button is only enabled if the validation for all textboxes has passed.

I have performed for each textbox the following

selenium.Type(textbox_id, content); //where content is programmatically generated in each round of test selenium.FireEvent(textbox_id, "blur");

All the sign up info gets filled up, but non it's blur event triggered. SignUp button remain disabled. Also, I have written an exact same test in java, which passed without the slightest bit of problem.

I would love to finish writing it in java, but I am restricted to the language I can use for this task; C#. Can someone tell me what might be causing this problem.

user940882
  • 31
  • 3

1 Answers1

0

I had the same problem and found a solution by reaching into the DOM and firing the blur event using javascript. I wrote the method as an extension method on IWebElement. See the code below:

public static void Blur(this IWebElement element)
{
    var jsExecutor = (IJavaScriptExecutor)Context.Driver;

    try
    {
        jsExecutor.ExecuteScript(
            @"var fireOnThis = arguments[0];
             fireOnThis.scrollIntoView(false);
             var evt = 'blur';      
             if( document.createEvent ) {
             var evObj = document.createEvent('MouseEvents');
             evObj.initEvent(evt, true, false);
             fireOnThis.dispatchEvent(evObj);
             } else if (document.createEventObject) {
            fireOnThis.fireEvent('on'+evt);
        }", element);
    }
    catch
    {}
}
Kevin Holditch
  • 5,165
  • 3
  • 19
  • 35