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

Method sendKeys

javascript/selenium-webdriver/lib/webdriver.js:2883–2918  ·  view source on GitHub ↗

* Types a key sequence on the DOM element represented by this instance. * * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is * processed in the key sequence, that key state is toggled until one of the * following occurs: * * - The modifier key is encounter

(...args)

Source from the content-addressed store, hash-verified

2881 * have been typed.
2882 */
2883 async sendKeys(...args) {
2884 let keys = []
2885 ;(await Promise.all(args)).forEach((key) => {
2886 let type = typeof key
2887 if (type === 'number') {
2888 key = String(key)
2889 } else if (type !== 'string') {
2890 throw TypeError('each key must be a number or string; got ' + type)
2891 }
2892
2893 // The W3C protocol requires keys to be specified as an array where
2894 // each element is a single key.
2895 keys.push(...key)
2896 })
2897
2898 if (!this.driver_.fileDetector_) {
2899 return this.execute_(
2900 new command.Command(command.Name.SEND_KEYS_TO_ELEMENT)
2901 .setParameter('text', keys.join(''))
2902 .setParameter('value', keys),
2903 )
2904 }
2905
2906 try {
2907 keys = await this.driver_.fileDetector_.handleFile(this.driver_, keys.join(''))
2908 } catch (ex) {
2909 this.log_.severe('Error trying parse string as a file with file detector; sending keys instead' + ex)
2910 keys = keys.join('')
2911 }
2912
2913 return this.execute_(
2914 new command.Command(command.Name.SEND_KEYS_TO_ELEMENT)
2915 .setParameter('text', keys)
2916 .setParameter('value', keys.split('')),
2917 )
2918 }
2919
2920 /**
2921 * Retrieves the element's tag name.

Callers

nothing calls this directly

Calls 6

execute_Method · 0.95
setParameterMethod · 0.80
severeMethod · 0.80
splitMethod · 0.80
forEachMethod · 0.45
handleFileMethod · 0.45

Tested by

no test coverage detected