Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Element reference not seen before: undefined' using geckodriver, waitForElementVisible fails #1332

Closed
fc opened this issue Jan 3, 2017 · 5 comments
Labels

Comments

@fc
Copy link

fc commented Jan 3, 2017

Info on Firefox (latest version):

  { XULappId: '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}',
     acceptSslCerts: false,
     appBuildId: '20161208153507',
     browserName: 'firefox',
     browserVersion: '50.1.0',
     command_id: 1,
     javascriptEnabled: true,
     marionette: true,
     name: 'Example',
     platform: 'DARWIN',
     platformName: 'darwin',
     platformVersion: '16.3.0',
     processId: 36947,
     proxy: {},
     raisesAccessibilityExceptions: false,
     rotatable: false,
     specificationLevel: 0,
     takesElementScreenshot: true,
     takesScreenshot: true,
     version: '50.1.0' } }

Firefox 50.1.0
geckodriver 0.11.1 using the geckodriver npm. (yes, there is a new geckodriver just released today! can test with that if necessary)
Nightwatch 0.9.12

Calling waitForElementVisible fails.

Verbose output from Nightwatch:

INFO Request: POST /session/73d25a14-97c1-4f48-8f0d-1ed8e4b58546/elements
 - data:  {"using":"css selector","value":"[data-slide=next]"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":52}
INFO Response 200 POST /session/73d25a14-97c1-4f48-8f0d-1ed8e4b58546/elements (9ms) { value: [ { 'element-6066-11e4-a52e-4f735466cecf': '6fac5fda-a4b1-e84d-9f0f-3028d7914619' } ] }
INFO Request: GET /session/73d25a14-97c1-4f48-8f0d-1ed8e4b58546/element/undefined/displayed
 - data:
 - headers:  {"Accept":"application/json"}
ERROR Response 500 GET /session/73d25a14-97c1-4f48-8f0d-1ed8e4b58546/element/undefined/displayed (7ms) { error: 'javascript error',
  message: 'Element reference not seen before: undefined' }

It looks like Nightwatch is expecting the property ELEMENT:
https://github.com/nightwatchjs/nightwatch/blob/master/lib/api/element-commands/_waitForElement.js#L217

But geckodriver/Firefox is returning:

[{ 'element-6066-11e4-a52e-4f735466cecf': '6fac5fda-a4b1-e84d-9f0f-3028d7914619' }]

So... I don't know enough about the moving parts involved in this. It seems like Nightwatch should just take the element value instead of checking for ELEMENT but is Firefox/geckodriver now returning everything as an element GUID key?

Thoughts?

In addition to this, perhaps Nightwatch could display the error in the regular Nightwatch output when an actual error occurs instead of having to enable verbose.

Also, here is the output from geckodriver:

1483483519616	geckodriver	INFO	Listening on 127.0.0.1:4444
1483483530614	mozprofile::profile	INFO	Using profile path /var/folders/x_/l3xzrvh9219gf68nm243s2mr0000gp/T/rust_mozprofile.jtM3s6Nq4iFk
1483483530617	geckodriver::marionette	INFO	Starting browser /Applications/Firefox.app/Contents/MacOS/firefox-bin
1483483530619	geckodriver::marionette	INFO	Connecting to Marionette on localhost:61994
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
1483483531097	Marionette	INFO	Listening on port 61994
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0

Quick and dirty fix for a brand new year:

self.element = Object.values( result.value[0] )[0];
@fc
Copy link
Author

fc commented Jan 4, 2017

After briefly poking around the Marionette source code:
https://github.com/mozilla/gecko-dev/blob/master/testing/marionette/element.js#L43

Look what we have here...

element.Key = "element-6066-11e4-a52e-4f735466cecf";
element.LegacyKey = "ELEMENT";

And, surprise, this is according to the WebDriver spec:
https://www.w3.org/TR/2016/WD-webdriver-20161129/#h-elements

The web element identifier is a constant with the string "element-6066-11e4-a52e-4f735466cecf"

PR would include something that is vaguely like this:

self.element = obj[ elementId.LegacyKey ] || obj[ elementId.Key ];

@fc
Copy link
Author

fc commented Jan 5, 2017

The cause of this appears to be because of how I was loading the geckodriver.

I loaded the geckodriver from the command line:

geckodriver -p 5555

Then in my nightwatch.json configuration I had this:

        "gecko": {
            "selenium_port": 5555,
            "selenium_host": "localhost",
            "default_path_prefix" : "",
            "launch_url": "http://localhost:8000",
            "desiredCapabilities": {
                "browserName": "firefox",
                "marionette": true,
                "acceptSslCerts": true
            },
            "selenium" : {
                "start_process" : false
            }
        }

Apparently that's the wrong approach to take since Selenium has Firefox support built-in but that doesn't guarantee Selenium will always just return the ELEMENT key in the future so going to keep this issue open.

Anyway...

To workaround the issue just setup a Firefox profile and set your webdriver.firefox.profile to an appropriate profile name - read here on one how to do that.

@beatfactor
Copy link
Member

Using geckodriver directly is not fully supported yet, full support will come in a future version.

@beatfactor
Copy link
Member

Related to #1285.

@stale
Copy link

stale bot commented Jul 21, 2021

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

@stale stale bot added the stale label Jul 21, 2021
@stale stale bot closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants