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.

emulate TAB button

keatskeats Members
edited November -1 in Sahi - Open Source
Hi Narayan,

How to emulate a TAB button on your keyboard in sahi script?

I actually wanted to add new row to a table, that can happen when i press tab button. We have javascript in application which does that.
But i am wondering how to key press TAB button using sahi script.

Please let me know.
Tagged:

Comments

  • narayannarayan Administrators
    Hi Keats,
    _keyPress(element, 9) should have done it, but it does not as seen on firefox. Will have a look at this.
  • keatskeats Members
    Hi Narayan,

    Any idea about this yet?
    For the above issue i got through with a work around then.
    Now i was trying to get below things to work.
    _keyPress(element, 9); - Tab
    _keyPress(element, 115);-F4

    It doesn't seem to work. Can you help me with this?
  • narayannarayan Administrators
    Keats,

    If you wish to move focus from one element to another using tab, this method won't work. The reason is that the browser does not interpret the tab key the same way as it interprets other keys. So emulating a keypress will not work. If your intention is to just remove focus from an element, it will automatically happen when you click or setValue in some other element (from the January 2010 versions). You can also explicitly call _blur(element) or _removeFocus(element) if you want.

    The function keys may also not work the same way. The new _keyPress actually takes an array also as the second parameter.

    _keyPress(element, [keyCode, charCode]).

    You can go to http://sahi.co.in/demo/eventSequence.htm to find the keycodes and charcodes. (Click "Add event listeners", check keyCode and charCode, and press F4 in the textbox on the right. You will see the various events in the textarea below it.)

    You could try
    _keyPress(element, [115, 0]);

    Regards,
    Narayan
  • sunnysunny Members
    Hi Narayan,

    I tried with the above code, but it is not working.
    please suggest a way how to press tab key, actually i need to get focus on password field.

    Thanks,
    Sarathy CR
  • dvasquezdvasquez Members
    edited March 2014
    Hi!
    I've managed to simulate the tab key by typing something + "\t" inside a field (using the java driver).
    It doesn't work just with "\t" you need to type some text before.

    element.type(value + "\t");
Sign In or Register to comment.