element.all(by.css('#options-ul li')).each(function (elem, index) {
return elem.evaluate('option').then(function (value) {
if (correctAns.indexOf(value.Id)!==-1) {
elem.click();
browser.sleep(5000);
quizPageElements.clickNextQn();
// browser.sleep(15000);
browser.waitForAngular();
}
});
});
获取错误
Failed: stale element reference: element is not attached to the page document
(Session info: chrome=60.0.3112.113)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.3.9600 x86_64)
StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=60.0.3112.113)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.3.9600 x86_64)
at WebDriverError (C:\Users\Mvision\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:27:5)
at StaleElementReferenceError (C:\Users\Mvision\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:227:5)
at Object.checkLegacyResponse (C:\Users\Mvision\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:505:15)
at parseHttpResponse (C:\Users\Mvision\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Users\Mvision\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
尝试将每个元素放入<ul>
标记内,并使用量角器中的evaluate函数获取范围变量的id并检查条件,然后单击选项元素,然后单击下一步按钮。有时会在evaluate函数中出现此错误。
答案 0 :(得分:0)
由于无法避免陈旧错误,我只是尝试在evaluate
函数中捕获错误,并在发生错误时继续单击元素。赞,
element.all(by.css('#options-ul li')).each(function (elem, index) {
return elem.evaluate('option').then(function (value) {
if (correctAns.indexOf(value.Id)!==-1) {
elem.click();
browser.sleep(5000);
quizPageElements.clickNextQn();
// browser.sleep(15000);
browser.waitForAngular();
}
},function(err){
//do operation to click a button
});
});