(
currentElement: WebdriverIO.Element,
commandName: string
)
| 6 | * into stale element exception errors |
| 7 | */ |
| 8 | export 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 | } |
no test coverage detected
searching dependent graphs…