fix(fill): use isVisible to be consistent with waitForSelector (#1539)

Fixes #1442.
This commit is contained in:
Dmitry Gozman 2020-03-25 14:40:42 -07:00 committed by GitHub
parent 60942d0af5
commit c01ad84bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View File

@ -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;
@ -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();

View File

@ -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>