18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

How to script ENTER / ESC key press in sahi?

jameztccjameztcc Members
edited November -1 in Sahi - Open Source
Hi,

is there a way to define other key presses e.g. ESC or ENTER in sahi scripts?

Web application (AJAX) response to keys instead of clicks etc.

thanks,
James Tan

Comments

  • narayannarayan Administrators
    Hi James,

    For ESC, use _keyPress(<accessor >, 27);

    For ENTER, use _keyPress(<accessor >, 13);

    Replace <accessor > by the element's accessor. Eg. _keyPress(_textbox("t1"), 27);

    This works on Firefox, but may or may not work on Internet Explorer. Please check on your application.

    Regards,
    Narayan
  • Hi Narayan,


    thanks for the very fast response! I will try it out out both IE, Opera and FF to confirm since I am using all these for browser compatibility testing.


    By the way, how do I know what numbers to use in future for other key presses? Are they documented somewhere or can I debug them using anything that you are aware of?


    thanks,
    James Tan
  • narayannarayan Administrators
    Hi James,

    Till we get a simpler way to do it, here is what you do to get the number (charCode or keyCode).

    Navigate to http://sahi.co.in/demo/eventSequence.htm

    There is a textbox just above the Clear button. Do your keypress on it. The generated events will be displayed in the textarea.

    If the charCode exists, use the charCode as the number. If charCode is 0 or undefined, use the keyCode.

    Regards,
    Narayan
  • Hi Narayan,

    thanks! The ESC and ENTER keys are working as intended. Await thankfully for updates to Sahi to incorporate this feature if possible. Thanks.

    By the way, I tried the "...eventSequence.htm" and saw a 'DIV' above the button and i tried to press ENTER in the box and elsewhere, unable to observe any updates/text in the text box.

    Got this js error in the browser instead after loaded the URL:
    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
    Timestamp: Wed, 10 Feb 2010 10:04:32 UTC


    Message: Object expected
    Line: 40
    Char: 1
    Code: 0
    URI: Link to eventSequence


    thanks,
    James Tan
  • narayannarayan Administrators
    Hi James,

    "Await thankfully for updates to Sahi to incorporate this feature if possible": _keyPress is already available. Am I missing something?

    Sorry about that error. Missed uploading a file. It should work now. Thanks for pointing out.

    Regards,
    Narayan
  • Wanted to thank you earlier for the nice script, it worked.

    Thanks a lot again,
    James Tan
This discussion has been closed.