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.

Simulate keyDown Function

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

I try to simulate a press on a F4 in a specific element.
I have a basic javascript on my web page that capture the key press.
I try to use :
_keyPress(_textbox("MY_ELEMENT"), [115, 0]);
_keyDown(_textbox("MY_ELEMENT"), [115, 0]);
_keyUp(_textbox("MY_ELEMENT"), [115, 0]);
_keyPressEvent(_textbox("MY_ELEMENT"), [115, 0]);
but without any success for the moment.
Thanks in advance for your help,
Regards,

HadanMarv

Comments

  • narayannarayan Administrators
    _keyDown(_textbox("MY_ELEMENT"), [115, 0]);
    _keyUp(_textbox("MY_ELEMENT"), [115, 0]);

    Would be the right thing to do.

    Also try

    _focus(_textbox("MY_ELEMENT"));
    _keyDown(_textbox("MY_ELEMENT"), [115, 0]);
    _keyUp(_textbox("MY_ELEMENT"), [115, 0]);
  • Thanks for your reply, but it still doesn't work for me.
    i check my capture event trigger and it's like this onKeyPress="try{capture_keys(event)}catch(err){};"
    When i use _keyPress(_textbox("MY_ELEMENT"), [115, 0]); it's insert data into my field.
    Have you any other ideas ?
    Regards,

    HadanMarv
  • I am trying to a press on enter on a text box in a popup with the below code,
    _keyDown(_textbox(1,_under(_div('Customer Item Number'))),[13,0]);
    but it doesnot work for me

    Thanks in advance for you r help
  • Hi Soumyaneni,
    Please have a look at the following link:
    http://sahi.co.in/w/_setFile
    

    It shows how files can be uploaded using native events(that includes simulating enter key press).
    You need to add 2 functions in you script (_typeNative and _typeNativeKeyCode) for this purpose and use them.

    If its unclear in some way, please do let me know.

    Regards.
Sign In or Register to comment.