MCPcopy
hub / github.com/codeceptjs/CodeceptJS / _locate

Method _locate

lib/helper/WebDriver.js:893–938  ·  view source on GitHub ↗

* Get elements by different locator types, including strict locator. * Should be used in custom helpers: * * ```js * this.helpers['WebDriver']._locate({name: 'password'}).then //... * ``` * * * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict lo

(locator, smartWait = false)

Source from the content-addressed store, hash-verified

891 * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
892 */
893 async _locate(locator, smartWait = false) {
894 if (store.debugMode) smartWait = false
895
896 // special locator type for Shadow DOM
897 if (this._isShadowLocator(locator)) {
898 if (!this.options.smartWait || !smartWait) {
899 const els = await this._locateShadow(locator)
900 return els
901 }
902
903 const els = await this._locateShadow(locator)
904 return els
905 }
906
907 // special locator type for ARIA roles
908 if (locator.role) {
909 return this._locateByRole(locator)
910 }
911
912 // Handle role locators passed as Locator instances
913 const matchedLocator = new Locator(locator)
914 if (matchedLocator.isRole()) {
915 return this._locateByRole(matchedLocator.locator)
916 }
917
918 if (!this.options.smartWait || !smartWait) {
919 if (this._isCustomLocator(locator)) {
920 const locatorObj = new Locator(locator)
921 return this.browser.custom$$(locatorObj.type, locatorObj.value)
922 }
923
924 const els = await this.$$(withStrictLocator(locator))
925 return els
926 }
927
928 await this._smartWait(locator)
929
930 if (this._isCustomLocator(locator)) {
931 const locatorObj = new Locator(locator)
932 return this.browser.custom$$(locatorObj.type, locatorObj.value)
933 }
934
935 const els = await this.$$(withStrictLocator(locator))
936 await this.defineTimeout({ implicit: 0 })
937 return els
938 }
939
940 _grabCustomLocator(locator) {
941 if (typeof locator === 'string') {

Callers 15

_resMethod · 0.95
grabWebElementsMethod · 0.95
grabWebElementMethod · 0.95
clickXYMethod · 0.95
attachFileMethod · 0.95
grabTextFromAllMethod · 0.95
grabHTMLFromAllMethod · 0.95
grabValueFromAllMethod · 0.95
grabAttributeFromAllMethod · 0.95
seeElementMethod · 0.95
dontSeeElementMethod · 0.95

Calls 9

_isShadowLocatorMethod · 0.95
_locateShadowMethod · 0.95
_locateByRoleMethod · 0.95
isRoleMethod · 0.95
_isCustomLocatorMethod · 0.95
_smartWaitMethod · 0.95
defineTimeoutMethod · 0.95
withStrictLocatorFunction · 0.85
$$Method · 0.80

Tested by

no test coverage detected