March 26, 2011

Simulate Enter key press

Here is  a sample script how to simulate the Enter key press...

Here we go ...............

package newone;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;

public class Enter extends SeleneseTestCase{

public Selenium selenium;
public SeleniumServer seleniumserver;

public void setUp() throws Exception {

seleniumserver = new SeleniumServer();
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");


public void testEnter() throws Exception
assertEquals("Google", selenium.getTitle());
selenium.type("q", "testing");
/*keyPress(locator, keySequence)

       * locator - an element locator
       * keySequence - Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
   //Simulates a user pressing and releasing a key (13 if for Enter button).
selenium.keyPress("btnG", "\13");
public void tearDown() throws InterruptedException{


Here 13 means Enter key.

Hope this will help you.............


  1. Hoѡdy! Do you know if they makе aany plugins to assist with SEO?
    I'm trying to gеt my blog to rank for some targeted keywords but
    I'm not seеing very good gains. If yߋu know of any pease ѕhare.

    Here is my web blog - tell me more v10 spanish software

  2. I do trust all of the ideas you have offered on your post.
    They're very convincing and will certainly work. Still,
    the posts are too quick for beginners. May just you please extend them a bit from next time?
    Thank you for the post.

    Feel free to surf to my web blog;


  3. افضل شركة تنظيف بالاحساء افضل شركة تنظيف بالاحساء
    افضل شركة تنظيف شقق بالدمام افضل شركة تنظيف شقق بالدمام
    افضل شركة تنظيف شقق بالمدينة المنورة افضل شركة تنظيف شقق بالمدينة المنورة
    افضل شركة تنظيف شقق بالرياض افضل شركة تنظيف شقق بالرياض