t.hover Method

Hovers the mouse pointer over a web page element. Chainable.

t.hover(selector [, options]) → this | Promise<any>
Parameter Type Description
selector Function | String | Selector | Snapshot | Promise The target page element (See Select Target Elements).
options (optional) Object Additional action options (see Options).

Use this action to invoke popup elements such as hint windows, popup menus or dropdown lists that appear when hovering over other elements.

The following example shows how to move the mouse pointer over a combo box to display the dropdown list, then select an item and check that the combo box value has changed.

import { Selector } from 'testcafe';


test('Should show hint on hover', async t => {
    await t

Select Target Elements

Use the selector parameter to identify the target of a DOM event.

You can pass any of the following objects as a selector:

  • A CSS selector string.

    test('Click submit', async t => {
        // Click will be performed on the first element
        // that matches the CSS selector.
        await t.click('#submit-button');
  • A selector.

    import { Selector } from 'testcafe';
    fixture`Parameter as Selector`
    const lastCheckbox = Selector('fieldset p:last-child [type="checkbox"]');
    test('Click last checkbox', async t => {
        // Click will be performed on the element selected by
        // the 'getLastItem' selector.
        await t.click(lastCheckbox);
  • A client-side function that returns a DOM element.

    test('Click first child of the body', async t => {
        // Click will be performed on the element returned by the function,
        // which is the third child of the document's body.
        await t.click(() => document.body.children[0]);
  • A DOM node snapshot.

    import { Selector } from 'testcafe';
    fixture`Parameter as DOM node snapshot`
    test('Click preferred interface', async t => {
        const preferredInterface = await Selector('#preferred-interface');
        // Click will be performed on the element whose snapshot
        // is specified. This is an element with the '#preferred-interface' ID.
        await t.click(preferredInterface);
  • A Promise returned by a selector.

    import { Selector } from 'testcafe';
    const submitButton = Selector('#submit-button');
    fixture`Parameter as Promise by Selector`
    test('Click submit', async t => {
        // Click will be performed on the element specified by the selector
        // as soon as the promise is resolved.
        await t.click(submitButton());

TestCafe waits for the target element to become visible before it executes an action. If this does not happen within the selector timeout, the test fails.

TestCafe cannot interact with background elements. If a different element overlaps the action target, TestCafe waits for this element to disappear. If this does not happen within the selector timeout, TestCafe performs the action with the element on top of the original target. Learn more about stacking and z-index on MDN.


The upload action is an exception to this rule — it does not check the visibility of the target input.


Mouse action options are used in t.drag and t.hover actions.

export interface MouseOptions {
    modifiers: {
        ctrl: boolean;
        alt: boolean;
        shift: boolean;
        meta: boolean;

    offsetX: number;
    offsetY: number;
    speed: number;
Parameter Type Description Default
ctrl, alt, shift, meta Boolean Indicate which modifier keys are to be pressed during the mouse action. false
offsetX, offsetY Number Mouse pointer coordinates that define a point where the action is performed or started. If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the target element. If an offset is a negative integer, they are calculated relative to the bottom-right corner. The center of the target element.
speed Number The speed of action emulation. Defines how fast TestCafe performs the action when running tests. A number between 1 (the maximum speed) and 0.01 (the minimum speed). If test speed is also specified in the CLI, API or in test code, the action speed setting overrides test speed. 1


import { Selector } from 'testcafe';

const sliderHandle = Selector('.ui-slider-handle');

fixture`Mouse options`

test('Set an estimate', async t => {
    await t
        .drag(sliderHandle, 360, 0, {
            offsetX:   10,
            offsetY:   10,
            modifiers: {
                shift: true,