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

Stale element reference causes waitForElementVisible to fail even when the element is visible. #687

Closed
rachna86 opened this issue Oct 16, 2015 · 3 comments
Labels

Comments

@rachna86
Copy link

Nightwatch version - 0.7.8
Browser - chrome 46.0
OS version - OS X Yosemite

I have the following code in my test -

browser.click('@element') 
.waitForElementVisible('@otherElement');

The waitForElementVisible command fails even when the element is visible on the page. In order to get around this issue I have to add a pause. On looking at the logs from the --verbose command option I see the following error:

ERROR Response 500 GET /wd/hub/session/da547091-91b7-4d4f-bd23-7bd70c5b48e6/element/9/displayed{ sessionId: 'da547091-91b7-4d4f-bd23-7bd70c5b48e6',
  status: 10,
  state: 'stale element reference',
  value: 
   { message: 'stale element reference: element is not attached to the page document\n  (Session info: chrome=46.0.2490.71)\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.10.5 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 5 milliseconds\nFor documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html\nBuild info: version: \'2.45.0\', revision: \'5017cb8\', time: \'2015-02-26 23:59:50\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.10.5\', java.version: \'1.7.0_71\'\nSession ID: e1483d8203011114ffff6f1b128d5d2e\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/f6/06dqw47j0bx4lwl4g__8hh300000gn/T/.org.chromium.Chromium.Gkb0Im}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=46.0.2490.71, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]',
     suppressed: [],
     localizedMessage: 'stale element reference: element is not attached to the page document\n  (Session info: chrome=46.0.2490.71)\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.10.5 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 5 milliseconds\nFor documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html\nBuild info: version: \'2.45.0\', revision: \'5017cb8\', time: \'2015-02-26 23:59:50\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.10.5\', java.version: \'1.7.0_71\'\nSession ID: e1483d8203011114ffff6f1b128d5d2e\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/f6/06dqw47j0bx4lwl4g__8hh300000gn/T/.org.chromium.Chromium.Gkb0Im}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=46.0.2490.71, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]',
     buildInformation: 
      { releaseLabel: '2.45.0',
        buildTime: '2015-02-26 23:59:50',
        class: 'org.openqa.selenium.internal.BuildInfo',
        buildRevision: '5017cb8',
        hCode: 592317409 },
     cause: null,
     systemInformation: 'System info: host: \'N/A\', ip: \'N/A\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.10.5\', java.version: \'1.7.0_71\'',
     supportUrl: 'http://seleniumhq.org/exceptions/stale_element_reference.html',
     class: 'org.openqa.selenium.StaleElementReferenceException',
     additionalInformation: '\nSession ID: e1483d8203011114ffff6f1b128d5d2e\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/f6/06dqw47j0bx4lwl4g__8hh300000gn/T/.org.chromium.Chromium.Gkb0Im}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=46.0.2490.71, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]',
     hCode: 1902705498 },
  class: 'org.openqa.selenium.remote.Response',
  hCode: 1491989218 }
INFO Request: GET /wd/hub/session/da547091-91b7-4d4f-bd23-7bd70c5b48e6/element/9/displayed 
 - data:   
 - headers:  {"Accept":"application/json"}

WaitForElementVisible command should retry to find the element on getting the stale element reference error.

@sknopf
Copy link
Collaborator

sknopf commented Oct 16, 2015

Sounds like a good improvement, we already do this for expect - https://github.com/nightwatchjs/nightwatch/blob/master/lib/api/expect/_baseAssertion.js#L188

@RebootJeff
Copy link

This would be a problem for waitForElementPresent too, right?

@rachna86
Copy link
Author

Apparently this issue is only for waitForElementVisible command.

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

4 participants