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

Function usingFirstElement

lib/helper/WebDriver.js:3283–3299  ·  view source on GitHub ↗
(els)

Source from the content-addressed store, hash-verified

3281}
3282
3283function usingFirstElement(els) {
3284 const rawIndex = store.currentStep?.opts?.elementIndex
3285 if (rawIndex != null && els.length > 1) {
3286 let elementIndex = rawIndex
3287 if (elementIndex === 'first') elementIndex = 1
3288 if (elementIndex === 'last') elementIndex = -1
3289 if (Number.isInteger(elementIndex) && elementIndex !== 0) {
3290 const idx = elementIndex > 0 ? elementIndex - 1 : els.length + elementIndex
3291 if (idx >= 0 && idx < els.length) {
3292 debug(`[Elements] Using element #${rawIndex} out of ${els.length}`)
3293 return els[idx]
3294 }
3295 }
3296 }
3297 if (els.length > 1) debug(`[Elements] Using first element out of ${els.length}`)
3298 return els[0]
3299}
3300
3301function assertOnlyOneElement(elements, locator, helper) {
3302 if (elements.length > 1) {

Callers 14

_withinBeginMethod · 0.85
clickXYMethod · 0.85
forceRightClickMethod · 0.85
scrollIntoViewMethod · 0.85
scrollToMethod · 0.85
moveCursorToMethod · 0.85
saveElementScreenshotMethod · 0.85
focusMethod · 0.85
blurMethod · 0.85
dragAndDropMethod · 0.85
waitForClickableMethod · 0.85
switchToMethod · 0.85

Calls 1

debugFunction · 0.85

Tested by

no test coverage detected