Fix clicking offscreen horizontally (#105)

This patch starts clicking in the center of the element area which is
visible in a viewport.

Fixes #103.
This commit is contained in:
JoelEinbinder 2017-07-24 16:14:32 -07:00 committed by Andrey Lushnikov
parent 0a3125434e
commit a24cec20f9
2 changed files with 12 additions and 2 deletions

View File

@ -332,8 +332,8 @@ class Frame {
element.scrollIntoViewIfNeeded(); element.scrollIntoViewIfNeeded();
let rect = element.getBoundingClientRect(); let rect = element.getBoundingClientRect();
return { return {
x: (rect.left + rect.right) / 2, x: (Math.max(rect.left, 0) + Math.min(rect.right, window.innerWidth)) / 2,
y: (rect.top + rect.bottom) / 2 y: (Math.max(rect.top, 0) + Math.min(rect.bottom, window.innerHeight)) / 2
}; };
}, selector); }, selector);
if (!center) if (!center)

View File

@ -911,6 +911,16 @@ describe('Puppeteer', function() {
await page.click('#button-80'); await page.click('#button-80');
expect(await page.$('#button-80', button => button.textContent)).toBe('clicked'); expect(await page.$('#button-80', button => button.textContent)).toBe('clicked');
})); }));
it('should click a partially obscured button', SX(async function() {
await page.navigate(PREFIX + '/input/button.html');
await page.$('button', button => {
button.textContent = 'Some really long text that will go offscreen';
button.style.position = 'absolute';
button.style.left = '368px';
});
await page.click('button');
expect(await page.evaluate(() => window.result)).toBe('Clicked');
}));
it('should select the text with mouse', SX(async function(){ it('should select the text with mouse', SX(async function(){
await page.navigate(PREFIX + '/input/textarea.html'); await page.navigate(PREFIX + '/input/textarea.html');
await page.focus('textarea'); await page.focus('textarea');