{"record":{"id":"add1085971f28e8c","repo":"SeleniumHQ/selenium","slug":"key-is-not-a-string-key","errorCode":null,"errorMessage":"key is not a string: ${key}","messagePattern":"key is not a string: (.+?)","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":400,"severity":"error","filePath":"javascript/selenium-webdriver/lib/input.js","lineNumber":253,"sourceCode":"Device.Type = {\n  KEY: 'key',\n  NONE: 'none',\n  POINTER: 'pointer',\n  WHEEL: 'wheel',\n}\n\n/**\n * @param {(string|Key|number)} key\n * @return {string}\n * @throws {!(InvalidArgumentError|RangeError)}\n */\nfunction checkCodePoint(key) {\n  if (typeof key === 'number') {\n    return String.fromCodePoint(key)\n  }\n\n  if (typeof key !== 'string') {\n    throw new InvalidArgumentError(`key is not a string: ${key}`)\n  }\n\n  key = key.normalize()\n  if (Array.from(key).length !== 1) {\n    throw new InvalidArgumentError(`key input is not a single code point: ${key}`)\n  }\n  return key\n}\n\n/**\n * Keyboard input device.\n *\n * @final\n * @see <https://www.w3.org/TR/webdriver/#dfn-key-input-source>\n */\nclass Keyboard extends Device {\n  /** @param {string} id the device ID. */\n  constructor(id) {","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/input.js#L235-L271","documentation":"Thrown by checkCodePoint() in input.js when the key argument is neither a number nor a string. This function validates keyboard input for BiDi/classic actions, requiring each key to be a single Unicode code point. Numbers are converted via String.fromCodePoint; non-string, non-number values are rejected.","triggerScenarios":"Passing null, undefined, an object, an array, or a boolean to keyboard actions (keyDown, keyUp, sendKeys) instead of a string, Key constant, or number. Passing a Key constant incorrectly or a variable that resolved to null.","commonSituations":"Dynamic key data that is null or undefined; passing a DOM event object instead of a key; using an unexported/undefined Key constant; passing an array of keys where a single key is expected; variable not initialized before use.","solutions":["Use Key constants from selenium-webdriver (Key.ENTER, Key.TAB, etc.) or single-character strings.","Validate the input before use: if (typeof key === 'string' || typeof key === 'number').","Ensure the variable holding the key is initialized and not null/undefined.","Use driver.actions().sendKeys(text) for typing strings, and keyDown/keyUp only for modifier keys."],"exampleFix":"// before\nactions.keyDown(someObject) // someObject is not a key\n// after\nconst { Key } = require('selenium-webdriver')\nactions.keyDown(Key.ENTER)","handlingStrategy":"type-guard","validationCode":"if (typeof key !== 'string' && typeof key !== 'number') {\n  throw new TypeError(`key must be a string, number, or Key; got ${typeof key}`)\n}","typeGuard":"/**\n * @param {*} k\n * @returns {boolean}\n */\nfunction isValidKeyInput(k) {\n  return typeof k === 'string' || typeof k === 'number'\n}","tryCatchPattern":null,"preventionTips":["Always use Key constants (Key.ENTER, Key.TAB) or single-character strings for keyboard actions.","Validate that key variables are initialized and are string/number before use.","Use sendKeys() for typing text; reserve keyDown/keyUp for single modifier keys.","Avoid passing DOM event objects or arrays where a single key is expected."],"tags":["input","keyboard","validation","type","actions"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}