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

8 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

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

    ReplyDelete
  4. Kuchi Jewels is a project of Gem & Gems which is a leading exporter since 2005 to onwards in all over the world. Our company has experienced, educated and motivated staff. Our main goal is to meet the international standard B2C and B2B export target with competitive prices and high quality products. choker necklace australia , choker necklace chile ,

    ReplyDelete