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)
|
||||
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();
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user