Skip to main content

Class: DOMInteractor

Defined in: packages/dom-core/src/DOMInteractor.ts:34

Implements​

  • Interactor

Constructors​

Constructor​

new DOMInteractor(rootEl?): DOMInteractor

Defined in: packages/dom-core/src/DOMInteractor.ts:35

Parameters​

rootEl?​

HTMLElement = document.documentElement

Returns​

DOMInteractor

Properties​

rootEl​

protected readonly rootEl: HTMLElement = document.documentElement

Defined in: packages/dom-core/src/DOMInteractor.ts:35

Methods​

activate()​

activate(locator): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:376

Activate the element matched by the locator without pointer geometry.

Uses userEvent.click, which ignores layout and coordinates, so it reaches a visually-hidden or covered input that a positional click would miss (e.g. MUI Rating's hidden <input type="radio">).

Parameters​

locator​

PartLocator

Locator used to find the target element

Returns​

Promise<void>

Promise resolved once the element has been activated

Throws​

If the element is not found

Implementation of​

Interactor.activate


blur()​

blur(locator, _option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:297

Remove focus from the element found by the locator.

Parameters​

locator​

PartLocator

Locator used to find the target element

_option?​

Partial<BlurOption>

Reserved for future use

Returns​

Promise<void>

Promise resolved when blur has been applied

Throws​

If the element is not found

Implementation of​

Interactor.blur


calculateMousePosition()​

protected calculateMousePosition(el, preferredPoint?): Point

Defined in: packages/dom-core/src/DOMInteractor.ts:66

Parameters​

el​

Element

preferredPoint?​

Point

Returns​

Point


click()​

click(locator, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:83

Dispatch a click event on the element that matches the locator.

Parameters​

locator​

PartLocator

Locator used to find the target element

option?​

ClickOption

Optional click configuration such as the click position

Returns​

Promise<void>

A promise that resolves after the event is triggered

Throws​

If the element is not found

Implementation of​

Interactor.click


contextMenu()​

contextMenu(locator): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:354

Dispatch a contextmenu (right-click) event on the element matched by the locator.

The element is focused first if focusable, mirroring pressKey, so the event originates from the active element as a real right-click would. A context menu has no aria-expanded/controlled-open path, so this dispatched event is the only way to exercise the menu-opening behavior.

Parameters​

locator​

PartLocator

Locator used to find the target element

Returns​

Promise<void>

Promise resolved once the event has been dispatched

Throws​

If the element is not found

Implementation of​

Interactor.contextMenu


drag()​

drag(locator, delta): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:603

Drag the located element by the given pixel delta from its center.

The sequence (mousedown at center → mousemove at center + delta → mouseup at center + delta) is synthesized with the shared dispatchMouse + calculateMousePosition pattern, using the caller-supplied delta for the move/up coordinates. jsdom has no layout, so the center resolves to zeros and only the event wiring is exercised — the behavioral outcome of the drag is E2E-only.

Only raw mouse events are fired; native HTML5 drag-and-drop is NOT synthesized — see #922.

Parameters​

locator​

PartLocator

Locator used to find the element to drag

delta​

Point

Pixel offset to drag by

Returns​

Promise<void>

Throws​

If the element is not found

Implementation of​

Interactor.drag


dragTo()​

dragTo(source, target): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:568

Drag the source element and drop it onto the target element.

The pointer sequence (mousedown on source → mousemove on target → mouseup on target) is synthesized with the shared dispatchMouse + calculateMousePosition pattern. jsdom has no layout, so those coordinates are all zeros — the event wiring (and any drop handler the sequence triggers) is exercised, but the positional outcome is E2E-only.

Only raw mouse events are fired; native HTML5 drag-and-drop (dragstart/dragover/drop + dataTransfer) is NOT synthesized, so components built on the HTML5 DnD API are not driven by this — see #922.

Parameters​

source​

PartLocator

Locator used to find the element to drag

target​

PartLocator

Locator used to find the drop target

Returns​

Promise<void>

Throws​

If either element is not found

Implementation of​

Interactor.dragTo


enterText()​

enterText(locator, text, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:393

Type text into the element matched by the locator.

Parameters​

locator​

PartLocator

Locator used to find the target element

text​

string

The string to type

option?​

Partial<EnterTextOption>

Options such as appending or replacing existing value

Returns​

Promise<void>

Promise resolved when typing has completed

Throws​

If the element is not found

Implementation of​

Interactor.enterText


exists()​

exists(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:630

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.exists


focus()​

focus(locator, _option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:278

Move focus to the element found by the locator.

Parameters​

locator​

PartLocator

Locator used to find the target element

_option?​

Partial<FocusOption>

Reserved for future use

Returns​

Promise<void>

Promise resolved when focus has been applied

Throws​

If the element is not found

Implementation of​

Interactor.focus


getAttribute()​

Call Signature​

getAttribute(locator, name, isMultiple): Promise<readonly string[]>

Defined in: packages/dom-core/src/DOMInteractor.ts:36

Parameters​
locator​

PartLocator

name​

string

isMultiple​

true

Returns​

Promise<readonly string[]>

Implementation of​

Interactor.getAttribute

Call Signature​

getAttribute(locator, name, isMultiple): Promise<Optional<string>>

Defined in: packages/dom-core/src/DOMInteractor.ts:37

Parameters​
locator​

PartLocator

name​

string

isMultiple​

false

Returns​

Promise<Optional<string>>

Implementation of​

Interactor.getAttribute

Call Signature​

getAttribute(locator, name): Promise<Optional<string>>

Defined in: packages/dom-core/src/DOMInteractor.ts:38

Parameters​
locator​

PartLocator

name​

string

Returns​

Promise<Optional<string>>

Implementation of​

Interactor.getAttribute


getBoundingRect()​

getBoundingRect(locator): Promise<BoundingRect>

Defined in: packages/dom-core/src/DOMInteractor.ts:700

Get the located element's bounding rectangle.

jsdom has no layout engine, so getBoundingClientRect returns all zeros: the rect is structurally valid but behaviorally meaningless. Real geometry is E2E-only.

Parameters​

locator​

PartLocator

Locator used to find the element to measure

Returns​

Promise<BoundingRect>

The element's bounding rectangle (a zero-rect under jsdom)

Throws​

If the element is not found

Implementation of​

Interactor.getBoundingRect


getElement()​

Call Signature​

getElement<T>(locator, isMultiple): Promise<readonly T[]>

Defined in: packages/dom-core/src/DOMInteractor.ts:635

Type Parameters​
T​

T extends Element = Element

Parameters​
locator​

PartLocator

isMultiple​

true

Returns​

Promise<readonly T[]>

Call Signature​

getElement<T>(locator, isMultiple): Promise<Optional<T>>

Defined in: packages/dom-core/src/DOMInteractor.ts:636

Type Parameters​
T​

T extends Element = Element

Parameters​
locator​

PartLocator

isMultiple​

false

Returns​

Promise<Optional<T>>

Call Signature​

getElement<T>(locator): Promise<Optional<T>>

Defined in: packages/dom-core/src/DOMInteractor.ts:637

Type Parameters​
T​

T extends Element = Element

Parameters​
locator​

PartLocator

Returns​

Promise<Optional<T>>


getInputValue()​

getInputValue(locator): Promise<Optional<string>>

Defined in: packages/dom-core/src/DOMInteractor.ts:649

Parameters​

locator​

PartLocator

Returns​

Promise<Optional<string>>

Implementation of​

Interactor.getInputValue


getSelectLabels()​

getSelectLabels(locator): Promise<Optional<readonly string[]>>

Defined in: packages/dom-core/src/DOMInteractor.ts:671

Get the select element's selected options' labels

Parameters​

locator​

PartLocator

Returns​

Promise<Optional<readonly string[]>>

Implementation of​

Interactor.getSelectLabels


getSelectValues()​

getSelectValues(locator): Promise<Optional<readonly string[]>>

Defined in: packages/dom-core/src/DOMInteractor.ts:661

Get the select element's selected options' values

Parameters​

locator​

PartLocator

Returns​

Promise<Optional<readonly string[]>>

Implementation of​

Interactor.getSelectValues


getStyleValue()​

getStyleValue(locator, propertyName): Promise<Optional<string>>

Defined in: packages/dom-core/src/DOMInteractor.ts:56

Get the value of a style property

Parameters​

locator​

PartLocator

propertyName​

CssProperty

Returns​

Promise<Optional<string>>

Implementation of​

Interactor.getStyleValue


getText()​

getText(locator): Promise<Optional<string>>

Defined in: packages/dom-core/src/DOMInteractor.ts:681

Parameters​

locator​

PartLocator

Returns​

Promise<Optional<string>>

Implementation of​

Interactor.getText


hasAttribute()​

hasAttribute(locator, name): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:780

Parameters​

locator​

PartLocator

name​

string

Returns​

Promise<boolean>

Implementation of​

Interactor.hasAttribute


hasCssClass()​

hasCssClass(locator, className): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:772

Parameters​

locator​

PartLocator

className​

string

Returns​

Promise<boolean>

Implementation of​

Interactor.hasCssClass


hover()​

hover(locator, _option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:113

Move the mouse over the element.

Parameters​

locator​

PartLocator

Locator used to find the target element

_option?​

HoverOption

Reserved for future use

Returns​

Promise<void>

A promise that resolves after the hover event

Throws​

If the element is not found

Implementation of​

Interactor.hover


innerHTML()​

innerHTML(locator): Promise<string>

Defined in: packages/dom-core/src/DOMInteractor.ts:789

Get the HTML of an element

Parameters​

locator​

PartLocator

Returns​

Promise<string>

Implementation of​

Interactor.innerHTML


isChecked()​

isChecked(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:709

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.isChecked


isDisabled()​

isDisabled(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:717

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.isDisabled


isError()​

isError(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:743

Whether the element is in an invalid/error state, signalled by aria-invalid="true" (the cross-widget convention; native validity state is not consulted).

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.isError


isReadonly()​

isReadonly(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:728

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.isReadonly


isRequired()​

isRequired(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:732

Whether the element is marked required, via the native required property or an aria-required="true" attribute.

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.isRequired


isVisible()​

isVisible(locator): Promise<boolean>

Defined in: packages/dom-core/src/DOMInteractor.ts:748

Parameters​

locator​

PartLocator

Returns​

Promise<boolean>

Implementation of​

Interactor.isVisible


mouseDown()​

mouseDown(locator, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:153

Dispatch a mousedown event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

option?​

Partial<MouseDownOption>

Allows specifying the mouse position relative to the element

Returns​

Promise<void>

Promise resolved when the event is dispatched

Throws​

If the element is not found

Implementation of​

Interactor.mouseDown


mouseEnter()​

mouseEnter(locator, _option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:242

Dispatch a mouseenter event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

_option?​

Partial<MouseEnterOption>

Reserved for future use

Returns​

Promise<void>

Promise resolved after the event dispatches

Throws​

If the element is not found

Implementation of​

Interactor.mouseEnter


mouseLeave()​

mouseLeave(locator, _option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:261

Dispatch a mouseleave event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

_option?​

Partial<MouseLeaveOption>

Reserved for future use

Returns​

Promise<void>

Promise resolved once the event is dispatched

Throws​

If the element is not found

Implementation of​

Interactor.mouseLeave


mouseMove()​

mouseMove(locator, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:129

Dispatch a mousemove event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

option?​

Partial<MouseMoveOption>

Allows specifying the mouse position relative to the element

Returns​

Promise<void>

A promise that resolves once the event has been dispatched

Throws​

If the element is not found

Implementation of​

Interactor.mouseMove


mouseOut()​

mouseOut(locator, _option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:225

Dispatch a mouseout event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

_option?​

Partial<MouseOutOption>

Reserved for future use

Returns​

Promise<void>

Promise resolved once the event is dispatched

Throws​

If the element is not found

Implementation of​

Interactor.mouseOut


mouseOver()​

mouseOver(locator, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:201

Dispatch a mouseover event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

option?​

Partial<HoverOption>

Optional mouse position relative to the element

Returns​

Promise<void>

Promise resolved once the event is dispatched

Throws​

If the element is not found

Implementation of​

Interactor.mouseOver


mouseUp()​

mouseUp(locator, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:177

Dispatch a mouseup event on the target element.

Parameters​

locator​

PartLocator

Locator used to find the target element

option?​

Partial<MouseUpOption>

Allows specifying the mouse position relative to the element

Returns​

Promise<void>

Promise resolved when the event is dispatched

Throws​

If the element is not found

Implementation of​

Interactor.mouseUp


pressKey()​

pressKey(locator, key, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:323

Dispatch a key press (keydown + keyup) on the element matched by the locator.

The element is focused first so the key originates from the active element, matching a real key press. fireEvent is used over userEvent.keyboard for determinism and because MUI handlers read event.key directly.

Parameters​

locator​

PartLocator

Locator used to find the target element

key​

string

A KeyboardEvent.key value, e.g. 'Escape', 'Backspace'

option?​

Partial<PressKeyOption>

Modifier flags folded into the event init as ctrlKey/shiftKey/altKey/metaKey, so a handler reading event.ctrlKey (etc.) sees the chord — see PressKeyOption

Returns​

Promise<void>

Promise resolved once the events have been dispatched

Throws​

If the element is not found

Implementation of​

Interactor.pressKey


scrollBy()​

scrollBy(locator, delta): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:532

Scroll the located element by the given pixel delta.

jsdom has no layout engine, so the scroll offset never changes — this is a no-op behaviorally. As with scrollIntoView, jsdom may not implement Element.prototype.scrollBy as a function, so the typeof guard prevents a TypeError and keeps the call a safe no-op that resolves; real scroll behavior is E2E-only.

Parameters​

locator​

PartLocator

Locator used to find the scrollable element

delta​

Point

Pixel offset to scroll by

Returns​

Promise<void>

Throws​

If the element is not found

Implementation of​

Interactor.scrollBy


scrollIntoView()​

scrollIntoView(locator): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:509

Scroll the located element into view.

jsdom has no layout engine, so this never produces an observable scroll — geometry stays zeroed and nothing becomes "visible". Worse, jsdom does not implement Element.prototype.scrollIntoView as a function in every version, so calling it unguarded would throw a TypeError. The typeof guard keeps this a safe no-op that resolves; real scrolling behavior is E2E-only.

Parameters​

locator​

PartLocator

Locator used to find the element

Returns​

Promise<void>

Throws​

If the element is not found

Implementation of​

Interactor.scrollIntoView


selectOptionValue()​

selectOptionValue(locator, values): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:457

Select one or more option values in a <select> element.

Parameters​

locator​

PartLocator

Locator used to find the select element

values​

string[]

Values of the options to select

Returns​

Promise<void>

Promise resolved when the options have been selected

Throws​

If the element is not found

Implementation of​

Interactor.selectOptionValue


setInputFiles()​

setInputFiles(locator, files): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:481

Set the selected files on an <input type="file"> element.

The interactor contract passes filesystem paths, but a file input's value cannot be assigned programmatically — the browser blocks it — so the FileList must be populated through userEvent.upload, which also fires the change event. jsdom has no filesystem and never reads file bytes; only File.name is observable, so each path is wrapped in an empty File named by its basename. The real bytes matter only to the Playwright layer, which reads the paths natively — keeping dom-core free of any node dependency.

Parameters​

locator​

PartLocator

Locator used to find the file input element

files​

string | string[]

One or more filesystem paths to upload

Returns​

Promise<void>

Promise resolved once the upload change event has fired

Throws​

If the element is not found

Implementation of​

Interactor.setInputFiles


setRangeValue()​

setRangeValue(locator, value): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:441

Set the value of a range input and fire its change event.

fireEvent.change assigns the value through the element's native value setter (which both sanitizes it to the input's step and lets React's value tracker observe the change) and dispatches the event so a controlled component re-renders. Typing (enterText) does not apply to a range input.

Parameters​

locator​

PartLocator

Locator used to find the range input element

value​

number

The numeric value to set

Returns​

Promise<void>

Promise resolved once the change event has fired

Throws​

If the element is not found

Implementation of​

Interactor.setRangeValue


waitUntil()​

waitUntil<T>(option): Promise<T>

Defined in: packages/dom-core/src/DOMInteractor.ts:625

Keep running a probe function until it returns a value that matches the terminate condition or timeout

Type Parameters​

T​

T

Parameters​

option​

WaitUntilOption<T>

Returns​

Promise<T>

The last value returned by the probe function

Implementation of​

Interactor.waitUntil


waitUntilComponentState()​

waitUntilComponentState(locator, option?): Promise<void>

Defined in: packages/dom-core/src/DOMInteractor.ts:618

Wait until the component is in the expected state such as the component's visibility or existence. If the component has not reached the expected state within the timeout, it will throw an error.

By default it waits until the component is attached to the DOM within 30 seconds.

Parameters​

locator​

PartLocator

The locator of the component to wait for

option?​

Partial<Readonly<WaitForOption>> = defaultWaitForOption

The option to configure the wait behavior

Returns​

Promise<void>

Implementation of​

Interactor.waitUntilComponentState