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

Function proceedSelect

lib/helper/Puppeteer.js:3609–3685  ·  view source on GitHub ↗
(context, el, option)

Source from the content-addressed store, hash-verified

3607}
3608
3609async function proceedSelect(context, el, option) {
3610 const role = await el.evaluate(e => e.getAttribute('role'))
3611 const options = Array.isArray(option) ? option : [option]
3612
3613 if (role === 'combobox') {
3614 this.debugSection('SelectOption', 'Expanding combobox')
3615 highlightActiveElement.call(this, el, context)
3616 const ariaOwns = await el.evaluate(e => e.getAttribute('aria-owns'))
3617 const ariaControls = await el.evaluate(e => e.getAttribute('aria-controls'))
3618 await el.click()
3619 await this._waitForAction()
3620
3621 const listboxId = ariaOwns || ariaControls
3622 let listbox = null
3623 if (listboxId) {
3624 const listboxEls = await context.$$( `#${listboxId}`)
3625 if (listboxEls.length) listbox = listboxEls[0]
3626 }
3627 if (!listbox) {
3628 const listboxEls = await findByRole.call(this, context, { role: 'listbox' })
3629 if (listboxEls?.length) listbox = listboxEls[0]
3630 }
3631
3632 if (listbox) {
3633 for (const opt of options) {
3634 const optEls = await findByRole.call(this, listbox, { role: 'option', name: opt })
3635 if (optEls?.length) {
3636 const optEl = optEls[0]
3637 this.debugSection('SelectOption', `Clicking: "${opt}"`)
3638 highlightActiveElement.call(this, optEl, context)
3639 await optEl.click()
3640 }
3641 }
3642 }
3643 return this._waitForAction()
3644 }
3645
3646 if (role === 'listbox') {
3647 for (const opt of options) {
3648 const optEls = await findByRole.call(this, el, { role: 'option', name: opt })
3649 if (optEls?.length) {
3650 const optEl = optEls[0]
3651 this.debugSection('SelectOption', `Clicking: "${opt}"`)
3652 highlightActiveElement.call(this, optEl, context)
3653 await optEl.click()
3654 }
3655 }
3656 return this._waitForAction()
3657 }
3658
3659 // Native <select> element
3660 const tagName = await el.evaluate(e => e.tagName)
3661 if (tagName !== 'SELECT') {
3662 throw new Error('Element is not <select>')
3663 }
3664 highlightActiveElement.call(this, el, context)
3665 const optionArray = Array.isArray(option) ? option : [option]
3666

Callers

nothing calls this directly

Calls 6

evaluateMethod · 0.80
getAttributeMethod · 0.80
$$Method · 0.80
clickMethod · 0.45
_waitForActionMethod · 0.45

Tested by

no test coverage detected