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, 2019 in Selenium by Kunal
206 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, 2019 by Sanjeev

Related Questions In Selenium

0 votes
1 answer

Can anyone demonstrate how navigation commands can be used on a webpage in Selenium?

Hey Amanprit, Navigation Commands are used to ...READ MORE

answered Jul 4, 2019 in Selenium by Anvi
• 14,150 points
156 views
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 Jul 15, 2019 in Selenium by Anvi
• 14,150 points
138 views
0 votes
1 answer

How can I perform mouse hover to a web element with ruby and selenium webdriver?

Hi Siddhart, checkout the following script to ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,040 points
1,112 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, 2019 in Selenium by Abha
• 28,040 points
413 views
0 votes
2 answers

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,520 points
5,562 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,070 points
6,169 views
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,890 points
3,825 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,070 points
4,709 views
0 votes
1 answer

How to perform double click using mouse actions in Selenium with Python?

Hi harsh, you can use ActionChains() class ...READ MORE

answered Jul 29, 2019 in Selenium by Abha
• 28,040 points
1,247 views
0 votes
1 answer