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

Method selectOption

lib/helper/Playwright.js:2378–2411  ·  view source on GitHub ↗

* {{> selectOption }}

(select, option, context = null)

Source from the content-addressed store, hash-verified

2376 * {{> selectOption }}
2377 */
2378 async selectOption(select, option, context = null) {
2379 const pageContext = await this.context
2380 const matchedLocator = new Locator(select)
2381
2382 let contextEl
2383 if (context) {
2384 const contextEls = await this._locate(context)
2385 assertElementExists(contextEls, context, 'Context element')
2386 contextEl = contextEls[0]
2387 }
2388
2389 // Strict locator
2390 if (!matchedLocator.isFuzzy()) {
2391 this.debugSection('SelectOption', `Strict: ${JSON.stringify(select)}`)
2392 const els = contextEl ? await findElements.call(this, contextEl, matchedLocator) : await this._locate(matchedLocator)
2393 assertElementExists(els, select, 'Selectable element')
2394 return proceedSelect.call(this, pageContext, selectElement(els, select, this), option)
2395 }
2396
2397 // Fuzzy: try combobox
2398 this.debugSection('SelectOption', `Fuzzy: "${matchedLocator.value}"`)
2399 const comboboxSearchCtx = contextEl || pageContext
2400 let els = await findByRole(comboboxSearchCtx, { role: 'combobox', name: matchedLocator.value })
2401 if (els?.length) return proceedSelect.call(this, pageContext, selectElement(els, select, this), option)
2402
2403 // Fuzzy: try listbox
2404 els = await findByRole(comboboxSearchCtx, { role: 'listbox', name: matchedLocator.value })
2405 if (els?.length) return proceedSelect.call(this, pageContext, selectElement(els, select, this), option)
2406
2407 // Fuzzy: try native select
2408 els = await findFields.call(this, select, context)
2409 assertElementExists(els, select, 'Selectable element')
2410 return proceedSelect.call(this, pageContext, selectElement(els, select, this), option)
2411 }
2412
2413 /**
2414 * {{> grabNumberOfVisibleElements }}

Callers 1

proceedSelectFunction · 0.45

Calls 5

_locateMethod · 0.95
isFuzzyMethod · 0.95
selectElementFunction · 0.90
assertElementExistsFunction · 0.70
findByRoleFunction · 0.70

Tested by

no test coverage detected