Handle Keyboard and Mouse Events using Web Driver:-

It is used to handle operation using keyboard events such as key-up,key-down, and mouse events such as mouse-over,mouse-enter,mouse-out, etc.

Selenium Web Driver provide Action class to manage these operations.


Actions ref = new Actions(driver);

Action ref1 = ref.moveToElement('elementname').build()

ref1.perform()



Example of Keyboard and MouseEvent:-

package contect_us;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class ActionExample {

public static void main(String[] args) {
System.setProperty("Webdriver.chromedriver", "c://chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.facebook.com/");
WebElement ele = driver.findElement(By.name("email"));
Actions ref = new Actions(driver);
Action ac = ref.moveToElement(ele).click().keyDown(ele,Keys.SHIFT).sendKeys(ele,"abcd").keyUp(ele,Keys.SHIFT).doubleClick(ele).contextClick().build();
ac.perform();




}

}



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post