How to use Robot Class in Selenium Web-driver and What it is?

Welcome to softwaretestingsensei platform of learning Hub for beginners Selenium Tutorials, In this session, we are going to discuss that how to use Robot class in Selenium Web-driver and what it is.

What is Robot Class in JAVA? Robot class is a special class in Java which will allow us to perform multiple tasks based on user scripts needs or according to requirement in scripting. In today session we are going to describe a very simple script piece for beginners which will help to give quick start to play with robot class.

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.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
public class robotclasssession
{
public void robotclasssession_test() throws Exception
{
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“http://www.facebook.com”);
driver.findElement(By.id(“email”)).sendKeys(“type your email here for which you are looking
for in testing”);
driver.findElement(By.id(“pass”)).sendKeys(“type password here against your id”);
Robot robot_var=new Robot();
robot_var.keyPress(KeyEvent.VK_ENTER);
robot_var.keyRelease(KeyEvent.VK_ENTER);
}
}

How to use Robot Class in Selenium Web-driver and What it is

Leave a Comment

Your email address will not be published. Required fields are marked *