1

Oke I have read this website: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html

and I added this line in the top of my code:

import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Mouse;

but the 'Method and Description' options don't appear in Eclipse when I start typing…

i'm trying:

driver.findElement(By.id("test")).clickAndHold();

but no options appear in Eclipse… what do i miss?

2 Answers 2

3

Object needs to be created for the Actions class and then you can perform the mouse action.

Steps:

  1. Actions class object needs to be created by passing the driver reference
  2. All the Actions can be generated using the Actions Class Object.
  3. Finally, you can build and perform the action.

Example:

WebElement element driver.findElement(By.id("test"));
Actions builder=new Actions(driver);
builder.moveToElement(element).clickAndHold().build().perform();
Sign up to request clarification or add additional context in comments.

Comments

1

The user-facing API for emulating complex user gestures. Use this class rather than using the Keyboard or Mouse directly.

Yes if you want to simulate mouse, keyboard action you will have to use actions class. Note that actions is a class and action is interface in Selenium.

to use methods present in actions class , like any ordinary way you have to instantiate it.

Actions action = new Actions(driver);  
action.click();
action.click(WebElement target)  
action.contextClick()   // right click
action.doubleClick()  
action.dragAndDrop(WebElement source, WebElement target)

and many more..

Note that You have to use perform() method if there is only single event you are simulating which is highly unlikely so if there is multiple events you are simulating you will have to build().perform()

Code :

action.doubleClick().perform();  

and :

action.clickAndHold(WebElement target).release().build().perform();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.