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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

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

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay