In this session you will be learning the importance of keyboard events in selenium automation and its significance in various applications with examples
You can download this example program by scrolling to the bottom on the description and also you can import the complete example programs from below GitHub Repository
github.com/knowledgeshare-technologies/SeleniumBas…
*******************************************************************
You can see step by step selenium sessions from below playlist
*******************************************************************
• How to handle WebTables using Selenium Web...
For regular updates you can join this Group
***********************************************
www.facebook.com/groups/4754296501308288
****************************************************
Overview on Keyboard Events
****************************************************
What are Keyboard Events
Pressing a Key/Keys on a Keyboard (or) user interaction with the keyboard
Different ways to automate Keyboard Events
Using sendKeys() method of WebElement class
Using Actions class
Using Robot class
What is the use to handle this Keyboard events
To perform Copy & Paste ( Control + c, Control + v)
Holding keys like Shift , Alt, F1 to F12 to perform some operations on Application
When mouse clicks are not happening in any applications
Mostly used to press Tab and Enter Keys in a form etc.,
***********************************************************
Example program for handling Keyboard Events.
***********************************************************
package com.seleniumbasics;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Keyboard_Events {
public static void main(String[] args) throws AWTException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("demowebshop.tricentis.com/register");
driver.manage().window().maximize();
driver.findElement(By.id("gender-male")).click();
//Method - 1
/*
Actions action=new Actions(driver); action.sendKeys(Keys.TAB);
action.sendKeys("test1"); action.sendKeys(Keys.TAB);
action.sendKeys("test2"); action.sendKeys(Keys.TAB);
action.sendKeys("testtt@gmail.com"); action.sendKeys(Keys.ENTER);
action.build().perform();
*/
//Method - 2
Actions action=new Actions(driver);
action.sendKeys(Keys.TAB)
.sendKeys("test1")
.sendKeys(Keys.TAB)
.sendKeys("test2")
.sendKeys(Keys.TAB)
.sendKeys("testtt@gmail.com")
.sendKeys(Keys.ENTER)
.build().perform();
//Using Robot Class - java based class
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(3000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
}
コメント