Failed: sendKeysToActiveElement error while invoking sendKeys to ENTER and other keystrokes using ChromeDriver Chrome with Protractor
This error message...
Failed: sendKeysToActiveElement
...implies that the ChromeDriver was unable to invoke sendKeys()
to the ActiveElement.
This issue started to surface when ChromeDriver / Chrome switched over to W3C support.
@AutomatedTester in the discussion UnsupportedOperationError: sendKeysToActiveElement with sendkeys mentions, this may be an issue within the Actions class within the Client bindings.
There should be a little shim in the bindings that make sure the same functionality is given on older commands that have been removed. This has been implemented in the core selenium binding.
The Python example:
def send_keys(self, *keys_to_send):"""Sends keys to current focused element.:Args: - keys_to_send: The keys to send. Modifier keys constants can be found in the 'Keys' class."""typing = keys_to_typing(keys_to_send)if self._driver.w3c: for key in typing: self.key_down(key) self.key_up(key)else: self._actions.append(lambda: self._driver.execute( Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {'value': typing}))return selfdef send_keys_to_element(self, element, *keys_to_send):"""Sends keys to an element.:Args: - element: The element to send keys. - keys_to_send: The keys to send. Modifier keys constants can be found in the 'Keys' class."""self.click(element)self.send_keys(*keys_to_send)return self
Solution
@barancev have already merged the required changes through the commit Renaming back 'py' directory, use of 'legacy_create_init' argument and this issue would get completely resolved with the next release of ChromeDriver v77.0 / Chrome v77.0.
The good news is ChromeDriver v77.0 is already released containing the following fixes. From the Release Notes of ChromeDriver v77.0:
- Resolved issue 2975: Webdriver Actions for keys (CONTROL, SHIFT etc..) not working in ChromeDriver 75.0.3770.8 [Pri-2]
- Resolved issue 2981: Chromedriver in W3C mode loses mouse state between Actions API calls [Pri-2]
Outro
Protractor.Key.Enter is not working in ChromeDriver v75.0.3770.8
Upgraded to chromeDriver 77 and still running into the same issue as mentioned above.await elem.sendKeys(protractor.Key.TAB);
also tried: await browser.actions().sendKeys(protractor.Key.TAB).perform();
`- Failed: sendKeysToActiveElement Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: 'GC02XYZ...', ip: 'fe80:xyz...', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '11.0.1' Driver info: driver.version: unknown``chromeDriver -vChromeDriver 77.0.3865.40`
When using chrome 74+ please add the below at configuration.js file
exports.config = { seleniumAddress : 'http://localhost:4444/wd/hub', specs: ['spec.js'], capabilities:{ 'browserName': 'chrome', 'goog:chromeOptions': { w3c: false } }};
Notes:refer the this linkhttps://github.com/angular/protractor/issues/5274#issuecomment-522258213