我严重陷入困境。我遇到过时的元素引用问题 7/10 次。 我的应用程序在操作完成后显示一个配置对话框。此消息出现一秒钟左右。我想阅读conf对话框的文本。
var confDial= element(by.id('dialog'));
browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);
confDial.getText().then(function(text1){
expect(text1).toBe(TextExpected);
});
我所做的是,等待操作完成后出现对话框,然后执行 getText()。但它在 browser.wait() 本身失败。错误是
Failed: stale element reference: element is not attached to the page document 09:14:52 (Session info: chrome=52.0.2743.116) 09:14:52 (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-42-generic x86_64) (WARNING: The server did not provide any stacktrace information) 09:14:52 Command duration or timeout: 76 milliseconds 09:14:52 For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
如何解决它?
提前致谢。
最佳答案
据我所知,visibilityOf(element)
需要存在。
因此,您应该首先等待该元素出现。
试试这个:
browser.wait(EC.presenceOf(element(by.id('dialog'))), FIFTY_SECONDS);
var confDial= element(by.id('dialog'));
browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);
//expect already resolves a promise, so no need for a then() here.
expect(confDial.getText()).toBe(TextExpected);
//confDial.getText().then(function(text1){
// expect(text1).toBe(TextExpected);
//});
事件。这样它也可以工作(尽管不是陛下):
browser.wait(EC.presenceOf(var confDial = element(by.id('dialog'))), FIFTY_SECONDS);
关于javascript - Protractor:陈旧元素引用位于 "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46851915/