Skip to content

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

fix: allow setting input files for detached <input> elements (#5467)

Andrey Lushnikov6b40d75d0394
diff --git a/src/server/dom.ts b/src/server/dom.ts
index 5197b22a2e..16face0140 100644
--- a/src/server/dom.ts
+++ b/src/server/dom.ts
@@ -529,8 +529,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
const multiple = throwFatalDOMError(await this._evaluateInUtility(([injected, node]): 'error:notinput' | 'error:notconnected' | boolean => {
if (node.nodeType !== Node.ELEMENT_NODE || (node as Node as Element).tagName !== 'INPUT')
return 'error:notinput';
- if (!node.isConnected)
- return 'error:notconnected';
const input = node as Node as HTMLInputElement;
return input.multiple;
}, {}));
diff --git a/test/page-set-input-files.spec.ts b/test/page-set-input-files.spec.ts
index cf69149b62..3e7640489d 100644
--- a/test/page-set-input-files.spec.ts
+++ b/test/page-set-input-files.spec.ts
@@ -104,15 +104,20 @@ it('should work when file input is attached to DOM', async ({page, server}) => {
});
it('should work when file input is not attached to DOM', async ({page, server}) => {
- const [chooser] = await Promise.all([
- page.waitForEvent('filechooser'),
- page.evaluate(() => {
+ const [,content] = await Promise.all([
+ page.waitForEvent('filechooser').then(chooser => chooser.setFiles(FILE_TO_UPLOAD)),
+ page.evaluate(async () => {
const el = document.createElement('input');
el.type = 'file';
el.click();
+ await new Promise(x => el.oninput = x);
+ const reader = new FileReader();
+ const promise = new Promise(fulfill => reader.onload = fulfill);
+ reader.readAsText(el.files[0]);
+ return promise.then(() => reader.result);
}),
]);
- expect(chooser).toBeTruthy();
+ expect(content).toBe('contents of the file');
});
it('should not throw when filechooser belongs to iframe', (test, { browserName }) => {