Skip to content

VM Code SDK v2 / Selector

Class: Selector

Implements

  • ISelector

Methods

$()

$(s, options): Selector

Creates a new selector based on the given string and options.

Parameters

s: string

The selector string.

options: SelectorOptions

Options for the selector.

Returns

Selector

A new Selector instance.

Implementation of

ISelector.$

Throws

Will throw an error if the target is unknown or invalid.


[asyncIterator]()

[asyncIterator](): AsyncGenerator<Selector, void, unknown>

Returns

AsyncGenerator<Selector, void, unknown>

Implementation of

ISelector.[asyncIterator]


allInnerTexts()

allInnerTexts(): Promise<string[]>

Gets all inner texts of the elements.

Returns

Promise<string[]>

An array of inner texts.

Implementation of

ISelector.allInnerTexts


allTextContents()

allTextContents(): Promise<string[]>

Gets all text contents of the elements.

Returns

Promise<string[]>

An array of text contents.

Implementation of

ISelector.allTextContents


check()

check(options): Promise<void>

Checks the element.

Parameters

options: CheckOptions= {}

Options for the check action.

Returns

Promise<void>

Implementation of

ISelector.check

Throws

Will throw an error if the operation fails.


click()

click(options): Promise<void>

Clicks the element.

Parameters

options: ClickOptions= {}

Options for the click action.

Returns

Promise<void>

Implementation of

ISelector.click

Throws

Will throw an error if the operation fails.


count()

count(): Promise<number>

Gets the count of elements.

Returns

Promise<number>

The count of elements.

Implementation of

ISelector.count


eq()

eq(selector): boolean

Checks if the given selector is equal to the current selector.

Parameters

selector: ISelector

The selector to compare.

Returns

boolean

True if the selectors are equal, false otherwise.

Implementation of

ISelector.eq


evaluate()

evaluate<Arg, R>(jsCode, arg, options): Promise<R>

Evaluates JavaScript code in the context of the element.

Type parameters

Arg

R

Parameters

jsCode: string | (on, arg2) => R | Promise<R>

The JavaScript code to evaluate.

arg: Arg

The argument to pass to the JavaScript code.

options= {}

Options for the timeout.

options.timeout?: number

Returns

Promise<R>

The result of the evaluation.

Implementation of

ISelector.evaluate

Throws

Will throw an error if the operation fails.


evaluateAll()

evaluateAll<Arg, R>(jsCode, arg): Promise<R>

Evaluates JavaScript code in the context of all matching elements.

Type parameters

Arg

R

Parameters

jsCode: string | (on, arg2) => R | Promise<R>

The JavaScript code to evaluate.

arg: Arg

The argument to pass to the JavaScript code.

Returns

Promise<R>

The result of the evaluation.

Implementation of

ISelector.evaluateAll

Throws

Will throw an error if the operation fails.


fill()

fill(value, options): Promise<void>

Fills the element with the given value.

Parameters

value: string

The value to fill.

options: SelectOptionOptions= {}

Options for the fill action.

Returns

Promise<void>

Implementation of

ISelector.fill

Throws

Will throw an error if the operation fails.


first()

first(iteratorOptions): Selector

Gets the first element matching the iterator options.

Parameters

iteratorOptions: IteratorOptions

Options for the iterator.

Returns

Selector

A new Selector instance.

Implementation of

ISelector.first


getAttribute()

getAttribute(attribute, options): Promise<null | string>

Gets the attribute of the element.

Parameters

attribute: string

The attribute to get.

options: TimeoutOption= {}

Options for the timeout.

Returns

Promise<null | string>

The attribute value.

Implementation of

ISelector.getAttribute

Throws

Will throw an error if the operation fails.


innerHTML()

innerHTML(options): Promise<string>

Gets the inner HTML of the element.

Parameters

options: TimeoutOption= {}

Options for the timeout.

Returns

Promise<string>

The inner HTML as a string.

Implementation of

ISelector.innerHTML

Throws

Will throw an error if the operation fails.


innerText()

innerText(options): Promise<string>

Gets the inner text of the element.

Parameters

options: TimeoutOption= {}

Options for the timeout.

Returns

Promise<string>

The inner text as a string.

Implementation of

ISelector.innerText

Throws

Will throw an error if the operation fails.


last()

last(iteratorOptions): Selector

Gets the last element matching the iterator options.

Parameters

iteratorOptions: IteratorOptions

Options for the iterator.

Returns

Selector

A new Selector instance.

Implementation of

ISelector.last


match()

match(selectors, options): Promise<undefined | ISelector>

Matches the element against a list of selectors.

Parameters

selectors: (string | ISelector)[]

The list of selectors.

options= {}

Options for the timeout.

options.timeout?: number

Returns

Promise<undefined | ISelector>

The matched selector.


nth()

nth(n): Selector

Gets the nth element.

Parameters

n: number

The index of the element.

Returns

Selector

A new Selector instance.

Implementation of

ISelector.nth


screenshot()

screenshot(options): Promise<Buffer>

Takes a screenshot of the element.

Parameters

options: SelectorScreenshotOptions

Options for the screenshot.

Returns

Promise<Buffer>

The screenshot buffer.

Implementation of

ISelector.screenshot

Throws

Will throw an error if the operation fails.


scrollIntoViewIfNeeded()

scrollIntoViewIfNeeded(options): Promise<void>

Scrolls the element into view if needed.

Parameters

options: TimeoutOption= {}

Options for the timeout.

Returns

Promise<void>

Implementation of

ISelector.scrollIntoViewIfNeeded

Throws

Will throw an error if the operation fails.


selectOption()

selectOption(values, options): Promise<void>

Selects an option in the element.

Parameters

values: string | string[]

The values to select.

options: SelectOptionOptions= {}

Options for the select action.

Returns

Promise<void>

Implementation of

ISelector.selectOption

Throws

Will throw an error if the operation fails.


selectText()

selectText(options): Promise<void>

Selects the text in the element.

Parameters

options: SelectTextOptions= {}

Options for the select text action.

Returns

Promise<void>

Implementation of

ISelector.selectText

Throws

Will throw an error if the operation fails.


setAttribute()

setAttribute(attribute, value, options): Promise<void>

Sets the attribute of the element.

Parameters

attribute: string

The attribute to set.

value: string

The value to set.

options: TimeoutOption= {}

Options for the timeout.

Returns

Promise<void>

Implementation of

ISelector.setAttribute

Throws

Will throw an error if the operation fails.


setIteratorOptions()

setIteratorOptions(iteratorOptions): ISelector

Sets the iterator options.

Parameters

iteratorOptions: IteratorOptions

Options for the iterator.

Returns

ISelector

The current selector instance.

Implementation of

ISelector.setIteratorOptions


solveImageCaptcha()

solveImageCaptcha(accept_if?, options?): Promise<string>

Parameters

accept_if?

options?: SolveImageCaptchOptions= {}

Returns

Promise<string>

Implementation of

ISelector.solveImageCaptcha


solveReCaptchaV2()

solveReCaptchaV2(accept_if?, options?): Promise<string>

Solves the ReCaptcha V2 challenge.

Parameters

accept_if?

Optional function to accept the captcha code.

options?: SolveReCaptchaOptions= {}

Options for solving the ReCaptcha.

Returns

Promise<string>

The captcha code as a string.

Implementation of

ISelector.solveReCaptchaV2

Throws

Will throw an error if no captcha provider is configured or if the captcha could not be solved.


toArray()

toArray(): Promise<Selector[]>

Converts the selector to an array.

Returns

Promise<Selector[]>

An array of elements.

Implementation of

ISelector.toArray


updateCount()

updateCount(): Promise<number>

Updates the count of elements.

Returns

Promise<number>

The updated count.

Implementation of

ISelector.updateCount


waitFor()

waitFor(options): Promise<Selector>

Waits for the element to be in a specific state.

Parameters

options: WaitForSelectorOptions= undefined

Options for waiting.

Returns

Promise<Selector>

The current selector instance.

Implementation of

ISelector.waitFor

Throws

Will throw an error if the operation fails.