mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(input): clicking an element should take into account frame position (#971)
This commit is contained in:
@@ -44,22 +44,22 @@ class ElementHandle extends JSHandle {
|
||||
* @return {!Promise<{x: number, y: number}>}
|
||||
*/
|
||||
async _visibleCenter() {
|
||||
const {center, error} = await this.executionContext().evaluate(element => {
|
||||
const error = await this.executionContext().evaluate(element => {
|
||||
if (!element.ownerDocument.contains(element))
|
||||
return {center: null, error: 'Node is detached from document'};
|
||||
return 'Node is detached from document';
|
||||
if (element.nodeType !== HTMLElement.ELEMENT_NODE)
|
||||
return {center: null, error: 'Node is not of type HTMLElement'};
|
||||
return 'Node is not of type HTMLElement';
|
||||
element.scrollIntoViewIfNeeded();
|
||||
const rect = element.getBoundingClientRect();
|
||||
const center = {
|
||||
x: (Math.max(rect.left, 0) + Math.min(rect.right, window.innerWidth)) / 2,
|
||||
y: (Math.max(rect.top, 0) + Math.min(rect.bottom, window.innerHeight)) / 2
|
||||
};
|
||||
return {center, error: null};
|
||||
}, this);
|
||||
if (error)
|
||||
throw new Error(error);
|
||||
return center;
|
||||
const {model} = await this._client.send('DOM.getBoxModel', {
|
||||
objectId: this._remoteObject.objectId
|
||||
});
|
||||
return {
|
||||
x: (model.content[0] + model.content[4]) / 2,
|
||||
y: (model.content[1] + model.content[5]) / 2
|
||||
};
|
||||
}
|
||||
|
||||
async hover() {
|
||||
|
||||
Reference in New Issue
Block a user