MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / fetchElementByJSFunction

Function fetchElementByJSFunction

packages/webdriverio/src/utils/index.ts:206–226  ·  view source on GitHub ↗
(
    selector: ElementFunction,
    scope: WebdriverIO.Browser | WebdriverIO.Element,
    referenceId?: string
)

Source from the content-addressed store, hash-verified

204}
205
206function fetchElementByJSFunction(
207 selector: ElementFunction,
208 scope: WebdriverIO.Browser | WebdriverIO.Element,
209 referenceId?: string
210): Promise<ElementReference | ElementReference[]> {
211 if (!('elementId' in scope)) {
212 // eslint-disable-next-line @typescript-eslint/no-explicit-any
213 return scope.execute(selector as any, referenceId)
214 }
215 /**
216 * use a regular function because IE does not understand arrow functions
217 */
218 const script = (function (elem: HTMLElement, id: string) {
219 return (selector as unknown as Function).call(elem, id)
220 }).toString().replace('selector', `(${selector.toString()})`)
221 const args: (WebdriverIO.Element | string)[] = [scope as WebdriverIO.Element]
222 if (referenceId) {
223 args.push(referenceId)
224 }
225 return getBrowserObject(scope).executeScript(`return (${script}).apply(null, arguments)`, args)
226}
227
228export function isElement(o: Selector) {
229 return (

Callers 1

index.tsFile · 0.85

Calls 1

getBrowserObjectFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…