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

Function refetchElement

packages/webdriverio/src/utils/refetchElement.ts:8–41  ·  view source on GitHub ↗
(
    currentElement: WebdriverIO.Element,
    commandName: string
)

Source from the content-addressed store, hash-verified

6 * into stale element exception errors
7 */
8export default async function refetchElement (
9 currentElement: WebdriverIO.Element,
10 commandName: string
11): Promise<WebdriverIO.Element> {
12 const selectors: {
13 selector: Selector
14 index: number
15 }[] = []
16
17 /**
18 * Crawl back to the browser object, and cache all selectors
19 */
20 while (currentElement.elementId && currentElement.parent) {
21 selectors.push({ selector: currentElement.selector, index: currentElement.index || 0 })
22 currentElement = currentElement.parent as WebdriverIO.Element
23 }
24 selectors.reverse()
25
26 const length = selectors.length
27
28 /**
29 * Beginning with the browser object, re-chain
30 */
31 return selectors.reduce(async (elementPromise, { selector, index }, currentIndex) => {
32 const resolvedElement = await elementPromise
33 let nextElement = index > 0 ? await resolvedElement.$$(selector as string)[index]?.getElement() : null
34 nextElement = nextElement || await resolvedElement.$(selector).getElement()
35 /**
36 * For error purposes, changing command name to '$' if we aren't
37 * on the last element of the array
38 */
39 return await implicitWait(nextElement, currentIndex + 1 < length ? '$' : commandName)
40 }, Promise.resolve(currentElement))
41}

Callers 2

elementErrorHandlerFunction · 0.85

Calls 2

implicitWaitFunction · 0.85
getElementMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…