MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _locateShadow

Method _locateShadow

lib/helper/WebDriver.js:838–870  ·  view source on GitHub ↗

* Locate Element within the Shadow Dom * * @param {object} locator

(locator)

Source from the content-addressed store, hash-verified

836 * @param {object} locator
837 */
838 async _locateShadow(locator) {
839 const shadow = locator.value ? locator.value : locator[SHADOW]
840 const shadowSequence = []
841 let elements
842
843 if (!Array.isArray(shadow)) {
844 throw new Error(`Shadow '${shadow}' should be defined as an Array of elements.`)
845 }
846
847 // traverse through the Shadow locators in sequence
848 for (let index = 0; index < shadow.length; index++) {
849 const shadowElement = shadow[index]
850 shadowSequence.push(shadowElement)
851
852 if (!elements) {
853 elements = await this.browser.$$(shadowElement)
854 } else if (Array.isArray(elements)) {
855 elements = await elements[0].shadow$$(shadowElement)
856 } else if (elements) {
857 elements = await elements.shadow$$(shadowElement)
858 }
859
860 if (!elements || !elements[0]) {
861 throw new Error(
862 `Shadow Element '${shadowElement}' is not found. It is possible the element is incorrect or elements sequence is incorrect. Please verify the sequence '${shadowSequence.join('>')}' is correctly chained.`,
863 )
864 }
865 }
866
867 this.debugSection('Elements', `Found ${elements.length} '${SHADOW}' elements`)
868
869 return elements
870 }
871
872 /**
873 * Smart Wait to locate an element

Callers 1

_locateMethod · 0.95

Calls 2

pushMethod · 0.80
$$Method · 0.80

Tested by

no test coverage detected