angular/components · error
No keys have been specified.
Error message
No keys have been specified.
What it means
Thrown by ProtractorElement.sendKeys when called with an empty keys array. Dispatching keys with nothing to send would still trigger a focus event, which the library considers an unexpected side effect, so it throws getNoKeysSpecifiedError instead.
Source
Thrown at src/cdk/testing/protractor/protractor-element.ts:185
modifiers = first;
rest = modifiersAndKeys.slice(1);
} else {
modifiers = {};
rest = modifiersAndKeys;
}
const modifierKeys = toProtractorModifierKeys(modifiers);
const keys = rest
.map(k => (typeof k === 'string' ? k.split('') : [keyMap[k]]))
.reduce((arr, k) => arr.concat(k), [])
// Key.chord doesn't work well with geckodriver (mozilla/geckodriver#1502),
// so avoid it if no modifier keys are required.
.map(k => (modifierKeys.length > 0 ? Key.chord(...modifierKeys, k) : k));
// Throw an error if no keys have been specified. Calling this function with no
// keys should not result in a focus event being dispatched unexpectedly.
if (keys.length === 0) {
throw getNoKeysSpecifiedError();
}
return this.element.sendKeys(...keys);
}
/**
* Gets the text from the element.
* @param options Options that affect what text is included.
*/
async text(options?: TextOptions): Promise<string> {
if (options?.exclude) {
return browser.executeScript(_getTextWithExcludedElements, this.element, options.exclude);
}
// We don't go through Protractor's `getText`, because it excludes text from hidden elements.
return browser.executeScript(`return (arguments[0].textContent || '').trim()`, this.element);
}
/**View on GitHub (pinned to 0411926e7d)
Solutions
- Pass at least one key or character: sendKeys('Enter') not sendKeys().
- Check that the array being spread is non-empty before calling.
- If only modifier keys are needed, send a chord explicitly with a real key, e.g. sendKeys(`${control}a`).
Example fix
// before await input.sendKeys(...keys); // keys may be [] // after if (keys.length) await input.sendKeys(...keys);
Defensive patterns
Strategy: validation
Validate before calling
if (!keys || keys.length === 0) return; // nothing to send await element.sendKeys(...keys);
Type guard
const hasKeys = (k: string[] | undefined): k is [string, ...string[]] => Array.isArray(k) && k.length > 0;
Try / catch
try { await element.sendKeys(...keys); } catch (e) { if ((e as Error).message.includes('No keys have been specified')) return; throw e; } Prevention
- Guard spread calls sendKeys(...arr) for empty arrays
- Ensure modifier-key tests also include a real key
When it happens
Trigger: Calling await element.sendKeys() with no arguments, with an array spread that is empty (sendKeys(...arr) where arr === []), or passing only falsy values filtered out upstream.
Common situations: Parameterized test helpers that accumulate keys and pass none (e.g. pressing only Ctrl via modifierKeys but no actual key), data-driven tests with an empty key list.
Related errors
- This TestElement was not created by the ProtractorHarnessEnv
- No keys have been specified.
- No keys have been specified.
- Index must not be negative
- No harness was located at index ${offset}
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/19c5632b639c1249.
Report an issue: GitHub.