mucsi96 / nightwatch-api

[DEPRECATED] Cross-runner API for Nightwatch.js
https://nightwatch-api.netlify.com/
MIT License
84 stars 64 forks source link

Result returned by the client.elements and client.element command is incorrect #830

Open Adrian-Tamas opened 4 years ago

Adrian-Tamas commented 4 years ago

The element/elements command returns different structures for the selenium element between nightwatch and nightwatch-api and you can no longer use them to there full potential

Expected Behavior

Nightwatch object returned { "ELEMENT": "0.26693227503345773-1" }

Current Behavior

Nightwatch-api object example { "element-6066-11e4-a52e-4f735466cecf": "f5ae481e-4855-4343-a0f6-00553f97b534" }

Steps to Reproduce (for bugs)

Example code: client -> nightwatch-api import

          await client.url("https://nightwatchjs.org/guide");
            await client.elements("css selector", "a", function (res) {
                    res.value.forEach(function (jsonWebElement) {
                        let jsonWebElementId = jsonWebElement.ELEMENT;
                        client.elementIdText(jsonWebElementId, function (jsonElement) {
                            let text = jsonElement.value;
                            console.log("link text " + text);
                        });
                    });
                });

Because there no longer is an ELEMENT property you can read to get the id to use further protocol actions based on that like elementIdText can no longer be used

Your Environment

Adrian-Tamas commented 4 years ago

Workaround for anyone facing this issue would be to get the object property from obj key since the name is random:

let jsonWebElementId = jsonWebElement[Object.keys(jsonWebElement)[0]];
ituradastra commented 4 years ago

I don't think this is a bug, but this is how webdriver behaves. The web element identifier is the string constant "element-6066-11e4-a52e-4f735466cecf". See: https://www.w3.org/TR/webdriver/#elements

Adrian-Tamas commented 4 years ago

Pure Nightwatch does not retrieve the element in the same way. Only the Nightwatch-Api returns the element this way, while Nightwatch returns it with the name of "ELEMENT" so that it easy to access the content. And while yes, that is how an identifier looks, it should not be returned as a key in a object but rather as a value to an easy to identify key (like ELEMENT for e.g.)