Browser.keys () does not work on Firefox 53.0 and webdriver.io

In Firefox, a browser browser error.

  Os: MacOs
 Firefox version: 53.0.3
 Geckodriver: 0.16.1
 Webdriver.io: 4.8

Please help me deal with this error.

Here are the magazines

  [17:11:35] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / url"
 [17:11:41] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / refresh"
 [17:11:45] COMMAND GET "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / window / current / size"
 [17:11:46] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / elements"
 [17:11:46] COMMAND GET "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / element / 0 / displayed"
 [17:11:46] COMMAND GET "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / element / 1 / displayed"
 [17:11:46] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / elements"
 [17:11:46] COMMAND GET "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / element / 0 / displayed"
 [17:11:46] COMMAND GET "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / element / 1 / displayed"
 [17:11:46] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / elements"
 [17:11:47] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / element / 0 / value"
 WARNING: the "keys" command will be depcrecated soon.  Please use a different command in order to avoid failures in your test after updating WebdriverIO.
 [17:11:47] COMMAND POST "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / keys"
 [17:11:47] COMMAND GET "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / screenshot"
 [17:11:48] Saved screenshot: ERROR_firefox_2017-06-03T00-11-47.734Z.png
 [17:11:48] COMMAND DELETE "/ wd / hub / session / 97804a03-d52a-4232-9e3c-41e1fac6a9c5 / cookie"
 Error: sendKeysToActiveElement
 Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
 System info: host: 'xxx.local', ip: '10 .142.4.252 ', os.name:' Mac OS X ', os.arch:' x86_64 ', os.version: '10 .12.5', java.version : '1.8.0_131'
 Driver info: driver.version: RemoteWebDriver
 Error: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.
     at Object.wait (/Users/xxxx/c3web/xxxx/node_modules/fibers/future.js:449:15)
     at Object.keys (/Users/xxxxx/node_modules/wdio-sync/build/index.js:264:31)
     at Object.exports.customCommands.selector (/Users/xxx/c3web/xxxx/testlib/browser/customCommands.js:158:17)
     at /Users/xxxx/node_modules/wdio-sync/build/index.js:191:29
     - - - - -
     at keys ("Enter") - index.js: 244: 37
     at elementIdValue ("0", "xxxyyyzzz") - index.js: 293: 3
+5
source share
3 answers

As @iamdanchiv noted in his answer, browser.keys() will be deprecated, but there is a workaround (and I have to provide a PR for this).

What browser.keys() does under the hood is to call /session/:sessionId/keys in the WebDriver JsonWire protocol. However, if you look at the list of endpoints in the W3C Webdriver specification, that endpoint is not listed. I believe that it was previously part of the list, but was dropped. Instead, the specification states to use the endpoint /session/:sessionId/element/:elementId/value , which you can use to call the webdriverio browser.elementIdValue(ID, value) method instead.

Now, if you read the /session/:sessionId/keys specifications mentioned in the Selenium documentation on JsonWireProtocol , it’s pretty easy to replicate using other WebDriver features. The endpoint /session/:sessionId/keys just does this:

Sends strokes of a key sequence to the active element.

There is an endpoint that we can call to capture the current active element, which is /session/:sessionId/element/active , which is displayed in webdriverio browser.elementActive() .

In this case, all we need to do is to redefine this browser.keys() to first find out what the active element is, and then send the keys to this element.

So, this is the solution to solve the problem, if you want to send browser.keys("hello world") :

 var result = browser.elementActive(); var activeElement = result.value && result.value.ELEMENT; if(activeElement){ browser.elementIdValue(activeElement, "hello world"); } 

Note that this does not replicate the behavior of /session/:sessionId/keys exactly, which also does this according to the Selenium documentation:

This command is similar to the send keys command in every aspect, except for implicit termination: modifiers are not freed at the end of the call. Rather, the state of the modifier keys is maintained between calls, so interaction with the mouse can be performed by pressing the modifier keys.

The above solution implicitly issues modifier keys such as "SHIFT", "CTRL" at the end of the key sequence. Therefore, if you want to hold the key and do interactions with the mouse, then you are out of luck, we may have to wait until browsers implement the Webdriver API. But if all you wanted to do was send "CTRL" + "C", you can just send an array of these keys:

 var result = browser.elementActive(); var activeElement = result.value && result.value.ELEMENT; if(activeElement){ browser.elementIdValue(activeElement, ["CTRL", "c"]); } 
+8
source

Well, this error pretty much explains that there is a problem with the keys command implementation: WARNING: the "keys" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO. WARNING: the "keys" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO. .

Currently, it only works with chromedriver in my test cases, but I also cannot associate commands with it. (simulate Ctrl+C , Ctrl+V ).

See my answer to this question. You will need to find another way around this or wait for drivers ( chromedriver , geckodriver , etc.) to implement the new Selenium actions methods.

The answer I gave there pretty much covers the whole problem. Alternatively, you can try the code : browser.keys("\uE007") .

Hope this helps you!

0
source

Try with version webdriverio> v4.9.3, it seems they fixed it: https://github.com/webdriverio/webdriverio/commit/1f1db4583f62c60c7907f14c080603376e7ec52b

0
source

Source: https://habr.com/ru/post/1268497/


All Articles