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

Method forceClick

lib/helper/Puppeteer.js:1271–1294  ·  view source on GitHub ↗

* {{> forceClick }} *

(locator, context = null)

Source from the content-addressed store, hash-verified

1269 *
1270 */
1271 async forceClick(locator, context = null) {
1272 let matcher = await this.context
1273 if (context) {
1274 const els = await this._locate(context)
1275 assertElementExists(els, context)
1276 matcher = els[0]
1277 }
1278
1279 const els = await findClickable.call(this, matcher, locator)
1280 if (context) {
1281 assertElementExists(els, locator, 'Clickable element', `was not found inside element ${new Locator(context).toString()}`)
1282 } else {
1283 assertElementExists(els, locator, 'Clickable element')
1284 }
1285 const elem = els[0]
1286 return this.executeScript(el => {
1287 if (document.activeElement instanceof HTMLElement) {
1288 document.activeElement.blur()
1289 }
1290 const event = document.createEvent('MouseEvent')
1291 event.initEvent('click', true, true)
1292 return el.dispatchEvent(event)
1293 }, elem)
1294 }
1295
1296 /**
1297 * {{> clickLink }}

Callers 5

testsFunction · 0.45
coverage_test.jsFile · 0.45

Calls 5

_locateMethod · 0.95
executeScriptMethod · 0.95
assertElementExistsFunction · 0.70
toStringMethod · 0.45
blurMethod · 0.45

Tested by

no test coverage detected