Failed: sendKeysToActiveElement error while invoking sendKeys to ENTER and other keystrokes using ChromeDriver Chrome with Protractor

╄→尐↘猪︶ㄣ 提交于 2019-12-31 03:19:09

问题


My Protractor tests that use sendKeys to press Enter or Tab failed today after I was auto-updated to Chrome 76.

This worked find yesterday on Chrome 75.

This is the code that used to work:

browser.actions().sendKeys(protractor.Key.TAB).perform();

The error message is

Failed: sendKeysToActiveElement 
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
    System info: host: 'DESKTOP-6JGLC4V', ip: '192.168.0.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_221'
    Driver info: driver.version: unknown

Our Angular application has drop-down menus where you have to click outside of the drop-down or press the Tab key to close it. So I'm not sending the key stroke to an input element. I've tried $('body').sendKeys(protractor.Key.TAB); but that doesn't seem to work.


回答1:


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 self
    
    def 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




回答2:


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 -v
ChromeDriver 77.0.3865.40`


来源:https://stackoverflow.com/questions/57419356/failed-sendkeystoactiveelement-error-while-invoking-sendkeys-to-enter-and-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!