* Performs click at specific coordinates. * If locator is provided, the coordinates are relative to the element's top-left corner. * If locator is not provided, the coordinates are relative to the body element. * * ```js * // Click at coordinates (100, 200) relative to body * I.cli
(locator, x, y)
| 1178 | * @returns {Promise<void>} |
| 1179 | */ |
| 1180 | async clickXY(locator, x, y) { |
| 1181 | // If locator is a number, treat it as X coordinate and use body as base |
| 1182 | if (typeof locator === 'number') { |
| 1183 | const globalX = locator |
| 1184 | const globalY = x |
| 1185 | locator = '//body' |
| 1186 | x = globalX |
| 1187 | y = globalY |
| 1188 | } |
| 1189 | |
| 1190 | // Locate the base element |
| 1191 | const res = await this._locate(withStrictLocator(locator), true) |
| 1192 | assertElementExists(res, locator, 'Element to click') |
| 1193 | const el = usingFirstElement(res) |
| 1194 | |
| 1195 | // Get element position and size to calculate top-left corner |
| 1196 | const location = await el.getLocation() |
| 1197 | const size = await el.getSize() |
| 1198 | |
| 1199 | // WebDriver clicks at center by default, so we need to offset from center to top-left |
| 1200 | // then add our desired x, y coordinates |
| 1201 | const offsetX = -(size.width / 2) + x |
| 1202 | const offsetY = -(size.height / 2) + y |
| 1203 | |
| 1204 | if (this.browser.isW3C) { |
| 1205 | // Use performActions for W3C WebDriver |
| 1206 | return this.browser.performActions([ |
| 1207 | { |
| 1208 | type: 'pointer', |
| 1209 | id: 'pointer1', |
| 1210 | parameters: { pointerType: 'mouse' }, |
| 1211 | actions: [ |
| 1212 | { |
| 1213 | type: 'pointerMove', |
| 1214 | origin: el, |
| 1215 | duration: 0, |
| 1216 | x: Math.round(offsetX), |
| 1217 | y: Math.round(offsetY), |
| 1218 | }, |
| 1219 | { type: 'pointerDown', button: 0 }, |
| 1220 | { type: 'pointerUp', button: 0 }, |
| 1221 | ], |
| 1222 | }, |
| 1223 | ]) |
| 1224 | } |
| 1225 | |
| 1226 | // Fallback for non-W3C browsers |
| 1227 | await el.moveTo({ xOffset: Math.round(offsetX), yOffset: Math.round(offsetY) }) |
| 1228 | return el.click() |
| 1229 | } |
| 1230 | |
| 1231 | /** |
| 1232 | * {{> forceRightClick }} |
nothing calls this directly
no test coverage detected