Wednesday 25 May 2022

Selenium Keyboard Actions | Selenium Keyboard and Mouse Events | Selenium Keys Down Example

                   In this post, we will see Selenium Keyboard Actions | Selenium Keyboard and Mouse Events | Selenium Keys Down Example 


Program Code

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 KeyboardActions {


public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://amazon.in");

driver.manage().window().maximize();

Actions a=new Actions(driver);

a.moveToElement(driver.findElement(By.xpath("//input[@id='twotabsearchtextbox']"))).click().keyDown(Keys.SHIFT).sendKeys("pen driver").build().perform();

Thread.sleep(2000);

a.sendKeys(Keys.BACK_SPACE).sendKeys(Keys.BACK_SPACE).build().perform();


}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=i-8kRlK84is

No comments:

Post a Comment