Function to trigger events in phamtomjs