How to work with Keyboard Keypress event using selenium webdriver?

Problem? :(

How to Pressing Enter Button, ARROW_DOWN, ARROW_UP of Keyboard using Selenium Webdriver?

Solution :)

Take sample code from PasteBIN

 

Enum Keys

Enum Keys

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class KeysTest {

 public static void main(String[] args) {
 WebDriver myTestDriver = new FirefoxDriver();
 myTestDriver.get("http://tinyurl.com/yhu7olp");
 myTestDriver.manage().window().maximize();
 myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys("a");
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);

myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);

myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);

myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_DOWN);
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_UP);
 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ARROW_UP);

 myTestDriver.findElement(By.xpath("//input[@class='ui-autocomplete-input']")).sendKeys(Keys.ENTER);

myTestDriver.quit();

 }

}
About these ads
Pupunzi

For a better web

Tech

News and reviews from the world of gadgets, gear, apps and the web

VentureBeat

News About Tech, Money and Innovation

Digital Inspiration

Technology, Software and Internet

Kenazari's Blog

Just another WordPress.com weblog

Thinkwareglobal's Blog

Just another WordPress.com weblog

Richfowler1's Blog

Just another WordPress.com weblog

Romaicus's Blog

Just another WordPress.com weblog

botlaguduri

Just another WordPress.com site

chandanag89

Just another WordPress.com site

meghshetty

Just another WordPress.com site

digitalmediaexpert

digital media expert blog

Mama Sherry

Just another mama blog

Different Journeys

Let's make life easier!

Thinking in Silverlight

Silverlight/WPF/Windows 8 Store App

LAW RESOURCE INDIA

LEGAL RESOURCE CENTRE / COURT JUDGMENTS / LEGAL ARCHIVES

BookConnect

Promoting Indian language Books

Mary Ann M-P's Blog

Selenium: My Take

Actively Lazy

Smart software development is avoiding as much work as possible, yet getting the job done

SAPonPower

An ongoing discussion about SAP infrastructure

SAP Career

Your Career Mentor

hrsapcertification

Just another WordPress.com site

The secret product manager

Thoughts about product management, AIX, Power Systems, and other things that interest me

Sap Certification Material . Com

Quality store for sap software and courses

Simon Les Flex's Blog

SAP Process Integration Specialist - NOW WE CAN DO BETTER!

Oracle Technologies Primer

Technical posts on OSB/WLS/AIA, Oracle SOA Suite, BPM and Fusion Middleware

Gilberto Holms

Java/SOA Architecture Blog

The Skeleton

Java code skeletons, tips and pointers

J@n van Zoggel

mumblings of a middleware minion

The Pragmatic Integrator

Hints and tips from a pragmatic integration specialist

briskwalk

The pace of life..

Optimalbg's Blog

Just another WordPress.com site

IT Jobs in USA

Keep the track of this Blog if you are looking out for some good Opportunities to work in USA....

Referral Jobs | Right Place to Get a Job

Hurry you are one Click away to get a job - Fresher Jobs for 2012, 2013 fresher’s and also high paid jobs for well Experienced IT professionals on Referal jobs.

ECC International

Consulting & Assessment. Learning Outsourcing. Technology Solutions. Training & Conferences. Managed Services. Learning on Demand.

Michael Korn's Blog

Musings on Life, Career, Faith and Technology

WORKINGWITHQTP

Just another WordPress.com weblog

Mirzasohail's Blog

QTP, Dot Net SQL Server

SQA and Testers Blog

Just another WordPress.com weblog

Expertqtp's Weblog

Just another WordPress.com weblog

Cammurali's Blog

Just another WordPress.com site

QTP Challenges 4 Experts

Just another WordPress.com site

saxenavinay

A great WordPress.com site

Suresh4qtp's Blog

Just another WordPress.com site

jonah95hill

This WordPress.com site is the cat’s pajamas

It's always something...

Just another WordPress.com weblog

Faculty of Information Technology - Lê Ngọc Tiến

Be Yourself! Simplify Our Goals! Nothing is Impossible!

Anti-Malware Testing

Thoughts on security product testing past and present