Skip to content

Commit f86ddac

Browse files
authored
docs: mention click(force) and dispatchEvent(click) in the click docs (#2136)
1 parent c49a6d7 commit f86ddac

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/input.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ Under the hood, this and other pointer-related methods:
122122
- wait for it to receive pointer events at the action point, for example, waits until element becomes non-obscured by other elements
123123
- retry if the element is detached during any of the above checks
124124

125+
#### Forcing the click
126+
127+
Sometimes, apps use non-trivial logic where hovering the element overlays it with another element that intercepts the click. This behavior is indistinguishable from a bug where element gets covered and the click is dispatched elsewhere. If you know this is taking place, you can bypass the actionability checks and force the click:
128+
129+
```js
130+
await page.click('button#submit', { force: true });
131+
```
132+
133+
#### Programmatic click
134+
135+
If you are not interested in testing your app under the real conditions and want to simulate the click by any means possible, you can trigger the [`HTMLElement.click()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click) behavior via simply dispatching a click event on the element:
136+
137+
```js
138+
await page.dispatchEvent('button#submit', 'click');
139+
```
140+
141+
125142
#### API reference
126143

127144
- [page.click(selector[, options])](./api.md#pageclickselector-options) — main frame
@@ -133,6 +150,9 @@ Under the hood, this and other pointer-related methods:
133150
- [page.hover(selector[, options])](./api.md#pagehoverselector-options) — main frame
134151
- [frame.hover(selector[, options])](./api.md#framehoverselector-options) — given frame
135152
- [elementHandle.hover([options])](./api.md#elementhandlehoveroptions) — given element
153+
- [page.dispatchEvent(selector, type)](./api.md#pagedispatcheventselector-type-eventinit-options) — main frame
154+
- [frame.dispatchEvent(selector, type)](./api.md#framedispatcheventselector-type-eventinit-options) — given frame
155+
- [elementHandle.dispatchEvent(type)](./api.md#elementhandledispatcheventtype-eventinit) — given element
136156

137157
<br/>
138158

0 commit comments

Comments
 (0)