DEV Community

Cover image for Alternatives: Actions-Class and Javascript Executer in Selenium
Anne Quinkenstein
Anne Quinkenstein

Posted on • Updated on

Alternatives: Actions-Class and Javascript Executer in Selenium

Action Class

perform operations from keyboard events and mouse events (even dragging-and-dropping, holding a key and then performing mouse operations, ..)
we can building a complex chain of events exactly like a user doing these manually
The Actions class implements the builder pattern to create a composite action containing a group of other actions.

We need to create an instance of the Actions class by passing the instance of driver class to the constructor in the following way:

Actions a = new Actions(driver); 
Enter fullscreen mode Exit fullscreen mode

then we can use the methods of the action Class like MouseOver, ContextClick/RightClick, DoubleClick ...

Image description

a.moveToElement(element).conextClick().build().performe(); 
Enter fullscreen mode Exit fullscreen mode
  1. before performing the action, you have to build the entire element. that enables to composit actions
  2. to execute it you have to invoke performe() !
a.moveToElement(textbox).click().keyDown(Keys.SHIFT).sendKeys("hello").build().performe(); 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)