'Simulates `event` on element identified by `locator`.
This keyword is useful if element has OnEvent handler that needs to be
explicitly invoked.
See `introduction` for details about locating elements.'

@keyword
def simulate(self, locator, event):

    element = self.find_element(locator)
    script = '\nelement    =    arguments[0];\neventName    =    arguments[1];\nif    (document.createEventObject)    {    //    IE\n                return    element.fireEvent(\'on\'    +    eventName,    document.createEventObject());\n}\nvar    evt    =    document.createEvent("HTMLEvents");\nevt.initEvent(eventName,    true,    true);\nreturn    !element.dispatchEvent(evt);\n                                '
    self.browser.execute_script(script, element, event)
