Skip to content
CodeKruPro

Hover over an element with the actions API

Automation taskMediumAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

Interviewers ask: "A menu opens only when the mouse is over it. How do you reach the item inside?" Hover with the actions API (Actions in Java, ActionChains in Python), wait for the item to appear, then click it. In this task you hover over a button on the Buttons page whose colour changes on hover; the Python lesson reads the colour before and after.

Mouse Hover Action

Mouse Hover Action

The Actions class provides advanced user interactions. moveToElement() simulates mouse hover.

On the Buttons page, the hover button (id="colorChangeOnHover") changes its background color when hovered.

Task:

  1. Navigate to https://testkru.com/Elements/Buttons
  2. Find the hover button
  3. Print its text
  4. Use Actions to hover over it
  5. Print "Hovered successfully"

Expected output:

Button text: Hover on me
Hovered successfully