我在Selenium webdriver(v2.41.0)之上使用Nightwatch.js(v0.5.6)构建了一个小的,但正在增长(希望)的集成测试套件。我总是偶然发现Element not found in the cache
错误,但我正在研究一个大型验证测试用例 - 一个包含超过24个单独测试和setUp()
的文件。我还没能完成这个测试,这是一个问题。
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
错误似乎总是发生在setUp()
函数的末尾,但我找不到阻止此缓存发生的答案。这是我的setUp()
函数:
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()');
});
});
})
}
最终,我明白了:
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
测试用例有所不同,但在等待元素&lt; #btnCreate&gt;在1000毫秒内可见时,它似乎总是失败“。更改ms I wait的次数只会更改错误中报告的ms数。
我可以在这做什么?我的脚本有问题吗?我读过的所有东西和我尝试过的一切都让我无处可去。
答案 0 :(得分:4)
如果有人经过,我通过反复试验找到的是:
.click()
加载或重新加载内容时,我都需要添加.pause()
。通常,.pause(1000)
就足够了,但偶尔需要更长时间。单独使用.waitForElementVisible()
很少能够始终如一地工作。.waitForElementVisible()
时,我都使用了默认超时30000
。对于较大的值,似乎没有任何惩罚。可能有更好的答案,但到目前为止,这对我来说效果相当不错。
我现在将此标记为答案,但如果某人有更好的策略,我愿意改变这一点。