DEV Community

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

Posted on • Edited 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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more