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;

@BeforeClass
public void setUp() throws Exception {

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

}

@Test
public void testEnter() throws Exception
{
selenium.open("http://www.google.co.in");
selenium.windowMaximize();
assertEquals("Google", selenium.getTitle());
Thread.sleep(1000);
selenium.type("q", "testing");
Thread.sleep(1000);
/*keyPress(locator, keySequence)
   Arguments:

       * 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");
Thread.sleep(1000);
}
@AfterClass
public void tearDown() throws InterruptedException{
selenium.stop();
seleniumserver.stop();
}

}


Here 13 means Enter key.

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

4 comments:

  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.
    Thanks!

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

    ReplyDelete
  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; Www.Foodvu.Com.Php53-12.Ord1-1.Websitetestlink.com

    ReplyDelete