Can anyone demonstrate how Actions class can be used to perform mouse and keyboard events using Selenium?

0 votes
Can anyone demonstrate how Actions class can be used to perform mouse and keyboard events using Selenium?
Jul 1 in Selenium by Kunal
16 views

1 answer to this question.

0 votes

Hey Kunal, Advanced User Interactions API handles the special keyboard and mouse events. It contains the Actions and the Action classes that are needed when executing these events. Following code snippet will allow you to perform Shift keys up and down and also to double click and right click on an element:

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();

driver.get("https://www.facebook.com");
WebElement txtUsername = driver.findElement(By.id("email"));

Actions builder = new Actions(driver);
Action seriesOfActions = builder
	.moveToElement(txtUsername)
	.click()
	.keyDown(txtUsername, Keys.SHIFT)
	.sendKeys(txtUsername, "hello")
	.keyUp(txtUsername, Keys.SHIFT)
	.doubleClick(txtUsername)
	.contextClick()
	.build();
	
seriesOfActions.perform() ;

}

answered Jul 2 by Sanjeev

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Can Robot class be used to handle mouse buttons in Selenium?

Hi Prerna, Yes you can handle mouse ...READ MORE

answered 5 days ago in Selenium by Anvi
• 10,310 points
7 views
0 votes
1 answer

How can Custom Firefox Profiles be created and used in Selenium?

Hi Vijay, to create Custom Firefox Profile ...READ MORE

answered May 24 in Selenium by Abha
• 16,440 points
28 views
0 votes
1 answer

How ID and Class can be used as a CSS Selector?

Hey Bruce, to identify a web element ...READ MORE

answered Jun 21 in Selenium by Abha
• 16,440 points
32 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
259 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
628 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
257 views
0 votes
1 answer