MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / type

Function type

javascript/atoms/typescript/type.ts:118–160  ·  view source on GitHub ↗
(element: Element, keys: string[], _optKeyboard?: unknown, optPersistModifiers?: boolean)

Source from the content-addressed store, hash-verified

116// The third argument (a keyboard to reuse) never crossed the wire and is
117// ignored.
118function type(element: Element, keys: string[], _optKeyboard?: unknown, optPersistModifiers?: boolean): void {
119 if (!holdsFocus(element)) {
120 if (!isInteractable(element)) {
121 throw botError(ELEMENT_NOT_INTERACTABLE, 'Element is not currently interactable and may not be manipulated')
122 }
123 scrollIntoView(element)
124 }
125
126 const keyboard = new Keyboard()
127 keyboard.moveCursor(element)
128
129 // A host whose shadow tree holds focus passes its keys to the field inside.
130 const receiver = holdsFocus(element) ? getActiveElementFrom(element) || element : element
131 // A read-only picker falls through to the keyboard, which fires the keys
132 // but edits nothing, as it does for a read-only text field.
133 if (isElement(receiver, 'INPUT') && PICKER_TYPES.has((receiver as HTMLInputElement).type) && isEditable(receiver)) {
134 if (setPickerValue(receiver as HTMLInputElement, keys.join(''))) {
135 return
136 }
137 }
138
139 for (const sequence of keys) {
140 for (const ch of Array.from(sequence)) {
141 if (ch === NULL) {
142 keyboard.releaseModifiers()
143 } else if ('\uE000' <= ch && ch <= '\uE03D') {
144 const key = WEBDRIVER_KEYS[ch]
145 if (!key) {
146 throw botError(INVALID_ARGUMENT, 'Unsupported WebDriver key: \\u' + ch.charCodeAt(0).toString(16))
147 }
148 pressWebDriverKey(keyboard, key)
149 } else if (ALIASES[ch]) {
150 tap(keyboard, ALIASES[ch])
151 } else {
152 typeCharacter(keyboard, ch)
153 }
154 }
155 }
156
157 if (!optPersistModifiers) {
158 keyboard.releaseModifiers()
159 }
160}
161
162// A modifier toggles; anything else is pressed and released.
163function pressWebDriverKey(keyboard: Keyboard, key: Key): void {

Callers 15

__repr__Method · 0.85
__repr__Method · 0.85
__repr__Method · 0.85
__init__Method · 0.85
scroll_from_originMethod · 0.85
__repr__Method · 0.85
__init__Method · 0.85
__post_init__Method · 0.85
_validate_enumMethod · 0.85
as_jsonMethod · 0.85
from_jsonMethod · 0.85

Calls 15

moveCursorMethod · 0.95
releaseModifiersMethod · 0.95
holdsFocusFunction · 0.85
isInteractableFunction · 0.85
botErrorFunction · 0.85
scrollIntoViewFunction · 0.85
getActiveElementFromFunction · 0.85
isEditableFunction · 0.85
setPickerValueFunction · 0.85
pressWebDriverKeyFunction · 0.85
tapFunction · 0.85
typeCharacterFunction · 0.85