Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozmanc01ad84bd445
diff --git a/src/injected/injected.ts b/src/injected/injected.ts
index 68377b6845..8a08094ae8 100644
--- a/src/injected/injected.ts
+++ b/src/injected/injected.ts
@@ -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();
diff --git a/test/page.spec.js b/test/page.spec.js
index b5cad536eb..567742c8f5 100644
--- a/test/page.spec.js
+++ b/test/page.spec.js
@@ -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>