Reputation: 41256
I have a small, but growing (hopefully) suite of integration tests that I've built using Nightwatch.js (v0.5.6) on top of the Selenium webdriver (v2.41.0). I've always gotten the occasional Element not found in the cache
error, but I'm working on a large validation test case - a file that contains over 2 dozen individual tests plus setUp()
. I haven't been able to finish running this test yet and that's a problem.
There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Element not found in the cache - perhaps the page has changed since it was looked up
The error always seems to occur right at the end of my setUp()
function, but I can't find the answer that will prevent this caching from happening. Here's my setUp()
function:
setUp: function(browser) {
console.log('Logging in & navigating to Eligibility Groups...');
login(browser, app.masterAdminUsername, app.masterAdminPassword)
// Navigate to Eligibility Groups
.waitForElementVisible('button[data-action="EligibilityGroups"]', 1000, function() {
browser
.click('button[data-action="EligibilityGroups"]', function() {
console.log('Link clicked. Waiting for #btnCreate to be visible');
browser
.waitForElementVisible('#btnCreate', 1000, function() {
console.log('Exiting setUp()');
});
});
})
}
Eventually, I get this:
There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 3.72 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'robwilkerson.local', ip: '172.20.1.112', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Session ID: 04f47f5c-fda0-f049-9ec1-1d3a40ac44fe
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=30.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
✖ Timed out while waiting for element <#btnCreate> to be visible for 1000 milliseconds. - expected "visible" but got: not visible
The test case varies, but it always seems to fail "while waiting for element <#btnCreate> to be visible for 1000 milliseconds". Changing the number of ms I wait only changes the number of ms reported in the error.
What can I do here? Is there something wrong with my scripts? Everything I've read and everything I've tried has gotten me nowhere.
Upvotes: 1
Views: 1932
Reputation: 41256
In case anyone drops by, what I've found through trial and error is:
.click()
loads or reloads content, I need to add a .pause()
. Usually, .pause(1000)
is sufficient, but longer is occasionally necessary. Using .waitForElementVisible()
alone rarely works consistently..waitForElementVisible()
, I've used a default timeout of 30000
. There doesn't seem to be any penalty for larger values.There may be better answers, but this has worked reasonably well for me so far.
I'm marking this as the answer for now, but am open to changing that if someone has a better strategy.
Upvotes: 5