Skip to content

Commit

Permalink
fix(fill): use isVisible to be consistent with waitForSelector (#1539)
Browse files Browse the repository at this point in the history
Fixes #1442.
  • Loading branch information
dgozman committed Mar 25, 2020
1 parent 60942d0 commit c01ad84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/injected/injected.ts
Expand Up @@ -155,15 +155,7 @@ class Injected {
if (node.nodeType !== Node.ELEMENT_NODE)
return 'Node is not of type HTMLElement';
const element = node as HTMLElement;
if (!element.isConnected)
return 'Element is not attached to the DOM';
if (!element.ownerDocument || !element.ownerDocument.defaultView)
return 'Element does not belong to a window';

const style = element.ownerDocument.defaultView.getComputedStyle(element);
if (!style || style.visibility === 'hidden')
return 'Element is hidden';
if (!element.offsetParent && element.tagName !== 'BODY')
if (!this.isVisible(element))
return 'Element is not visible';
if (element.nodeName.toLowerCase() === 'input') {
const input = element as HTMLInputElement;
Expand Down Expand Up @@ -192,9 +184,9 @@ class Injected {
textarea.selectionEnd = textarea.value.length;
textarea.focus();
} else if (element.isContentEditable) {
const range = element.ownerDocument.createRange();
const range = element.ownerDocument!.createRange();
range.selectNodeContents(element);
const selection = element.ownerDocument.defaultView.getSelection();
const selection = element.ownerDocument!.defaultView!.getSelection();
if (!selection)
return 'Element belongs to invisible iframe.';
selection.removeAllRanges();
Expand Down
7 changes: 6 additions & 1 deletion test/page.spec.js
Expand Up @@ -998,13 +998,18 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF
await page.goto(server.PREFIX + '/input/textarea.html');
await page.$eval('input', i => i.style.visibility = 'hidden');
const hiddenError = await page.fill('input', 'some value', { force: true }).catch(e => e);
expect(hiddenError.message).toBe('Element is hidden');
expect(hiddenError.message).toBe('Element is not visible');
});
it('should be able to fill the body', async({page}) => {
await page.setContent(`<body contentEditable="true"></body>`);
await page.fill('body', 'some value');
expect(await page.evaluate(() => document.body.textContent)).toBe('some value');
});
it('should fill fixed position input', async ({page}) => {
await page.setContent(`<input style='position: fixed;' />`);
await page.fill('input', 'some value');
expect(await page.evaluate(() => document.querySelector('input').value)).toBe('some value');
});
it('should be able to fill when focus is in the wrong frame', async({page}) => {
await page.setContent(`
<div contentEditable="true"></div>
Expand Down

0 comments on commit c01ad84

Please sign in to comment.