Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): clicking an element should take into account frame position #971

Merged
merged 2 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/ElementHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,27 @@ describe('Page', function() {
await button.tap();
expect(await page.evaluate(() => getResult())).toEqual(['Touchstart: 0', 'Touchend: 0']);
}));
it('should click the button inside an iframe', SX(async function() {
await page.goto(EMPTY_PAGE);
await page.setContent('<div style="width:100px;height:100px">spacer</div>');
const FrameUtils = require('./frame-utils');
await FrameUtils.attachFrame(page, 'button-test', PREFIX + '/input/button.html');
const frame = page.frames()[1];
const button = await frame.$('button');
await button.click();
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
}));
it('should click the button with deviceScaleFactor set', SX(async function() {
await page.setViewport({width: 400, height: 400, deviceScaleFactor: 5});
expect(await page.evaluate(() => window.devicePixelRatio)).toBe(5);
await page.setContent('<div style="width:100px;height:100px">spacer</div>');
const FrameUtils = require('./frame-utils');
await FrameUtils.attachFrame(page, 'button-test', PREFIX + '/input/button.html');
const frame = page.frames()[1];
const button = await frame.$('button');
await button.click();
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
}));
function dimensions() {
const rect = document.querySelector('textarea').getBoundingClientRect();
return {
Expand Down