0

The current scenario is, i need to change the existing title with the new title and i am not able to trigger the keyboard's "Enter" key while automation. below is the program which i have written

var z = casper.evaluate(function triggerKeyDownEvent() {
jQuery(".jqtree-selected > div:nth-child(1) > span:nth-child(1)").text("HIHELLO");
this.wait(5000);
var e = jQuery.Event("keydown");
e.which = 13;
e.keyCode = 13;
jQuery("jqtree-selected > div:nth-child(1) > span:nth-child(1)").trigger(e);
return true;
});

I can see that the name is changing but it is failing to trigger Enter key.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Prateek.Naik
  • 556
  • 4
  • 18
  • possible duplicate of [JS Testing: Trigger jQuery keypress event from CasperJS and PhanthomJS](http://stackoverflow.com/questions/23608685/js-testing-trigger-jquery-keypress-event-from-casperjs-and-phanthomjs) – Artjom B. Apr 29 '15 at 14:14

2 Answers2

0

Use jQuery.Event("keypress") instead of jQuery.Event("keydown").

Also, try putting the element in a variable first then use it to trigger the event.

sam100rav
  • 3,733
  • 4
  • 27
  • 43
0

This question already answers how to trigger any keypress events with jQuery:

Definitive way to trigger keypress events with jQuery

Community
  • 1
  • 1
Javier La Banca
  • 329
  • 4
  • 6
  • ,@ Artjom B i tried with all the options that you guys mentioned, but still it is not emulating the keyboard event. – Prateek.Naik May 04 '15 at 11:29