mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(fill): use isVisible to be consistent with waitForSelector (#1539)
Fixes #1442.
This commit is contained in:
parent
60942d0af5
commit
c01ad84bd4
@ -155,15 +155,7 @@ class Injected {
|
|||||||
if (node.nodeType !== Node.ELEMENT_NODE)
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
||||||
return 'Node is not of type HTMLElement';
|
return 'Node is not of type HTMLElement';
|
||||||
const element = node as HTMLElement;
|
const element = node as HTMLElement;
|
||||||
if (!element.isConnected)
|
if (!this.isVisible(element))
|
||||||
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')
|
|
||||||
return 'Element is not visible';
|
return 'Element is not visible';
|
||||||
if (element.nodeName.toLowerCase() === 'input') {
|
if (element.nodeName.toLowerCase() === 'input') {
|
||||||
const input = element as HTMLInputElement;
|
const input = element as HTMLInputElement;
|
||||||
@ -192,9 +184,9 @@ class Injected {
|
|||||||
textarea.selectionEnd = textarea.value.length;
|
textarea.selectionEnd = textarea.value.length;
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
} else if (element.isContentEditable) {
|
} else if (element.isContentEditable) {
|
||||||
const range = element.ownerDocument.createRange();
|
const range = element.ownerDocument!.createRange();
|
||||||
range.selectNodeContents(element);
|
range.selectNodeContents(element);
|
||||||
const selection = element.ownerDocument.defaultView.getSelection();
|
const selection = element.ownerDocument!.defaultView!.getSelection();
|
||||||
if (!selection)
|
if (!selection)
|
||||||
return 'Element belongs to invisible iframe.';
|
return 'Element belongs to invisible iframe.';
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
|
@ -998,13 +998,18 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF
|
|||||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||||
await page.$eval('input', i => i.style.visibility = 'hidden');
|
await page.$eval('input', i => i.style.visibility = 'hidden');
|
||||||
const hiddenError = await page.fill('input', 'some value', { force: true }).catch(e => e);
|
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}) => {
|
it('should be able to fill the body', async({page}) => {
|
||||||
await page.setContent(`<body contentEditable="true"></body>`);
|
await page.setContent(`<body contentEditable="true"></body>`);
|
||||||
await page.fill('body', 'some value');
|
await page.fill('body', 'some value');
|
||||||
expect(await page.evaluate(() => document.body.textContent)).toBe('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}) => {
|
it('should be able to fill when focus is in the wrong frame', async({page}) => {
|
||||||
await page.setContent(`
|
await page.setContent(`
|
||||||
<div contentEditable="true"></div>
|
<div contentEditable="true"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user