diff --git a/src/chromium/JSHandle.ts b/src/chromium/JSHandle.ts index 1d47671f2d..00c8256862 100644 --- a/src/chromium/JSHandle.ts +++ b/src/chromium/JSHandle.ts @@ -17,7 +17,7 @@ import * as path from 'path'; import { assert, debugError, helper } from '../helper'; -import { ClickOptions, Modifier, MultiClickOptions, PointerActionOptions, SelectOption, selectFunction } from '../input'; +import { ClickOptions, Modifier, MultiClickOptions, PointerActionOptions, SelectOption, selectFunction, fillFunction } from '../input'; import { CDPSession } from './Connection'; import { ExecutionContext } from './ExecutionContext'; import { Frame } from './Frame'; @@ -321,34 +321,7 @@ export class ElementHandle extends JSHandle { async fill(value: string): Promise { assert(helper.isString(value), 'Value must be string. Found value "' + value + '" of type "' + (typeof value) + '"'); - const error = await this.evaluate((element: HTMLElement) => { - if (element.nodeType !== Node.ELEMENT_NODE) - return 'Node is not of type HTMLElement'; - if (element.nodeName.toLowerCase() === 'input') { - const input = element as HTMLInputElement; - const type = input.getAttribute('type') || ''; - const kTextInputTypes = new Set(['', 'password', 'search', 'tel', 'text', 'url']); - if (!kTextInputTypes.has(type.toLowerCase())) - return 'Cannot fill input of type "' + type + '".'; - input.selectionStart = 0; - input.selectionEnd = input.value.length; - } else if (element.nodeName.toLowerCase() === 'textarea') { - const textarea = element as HTMLTextAreaElement; - textarea.selectionStart = 0; - textarea.selectionEnd = textarea.value.length; - } else if (element.isContentEditable) { - if (!element.ownerDocument || !element.ownerDocument.defaultView) - return 'Element does not belong to a window'; - const range = element.ownerDocument.createRange(); - range.selectNodeContents(element); - const selection = element.ownerDocument.defaultView.getSelection(); - selection.removeAllRanges(); - selection.addRange(range); - } else { - return 'Element is not an ,