问题描述
当我尝试等待DOM元素从我的量角器测试正在测试的网页上的当前DOM树中删除时,我遇到这个问题。当我尝试等待DOM元素隐藏时,我已经有一个挂起,这是由user2912739在另一个线程中提供的这个很好的技术。
I run into this issue whenever I try to wait until an DOM element is removed from the current DOM tree on the web page that my protractor test is testing. I already got a hang of it when I try to wait until a DOM element becomes hidden with this nice technique offered by user2912739 in another thread.
var el = element(by.css('.your-css-class'));
return browser.wait(protractor.until.elementIsNotVisible(el));
这样做很不错。但是,当等待从DOM树中删除的元素 .isDisplayed()
和 .isPresent()
或上述行似乎不起作用。测试将继续运行,但它似乎正在尝试获取该元素,但从未成功,因此最终会根据配置文件的超时设置超时。例如。这是日志。
This works pretty decent. However, when it comes to waiting for an element got removed from the DOM tree both .isDisplayed()
and .isPresent()
or the above lines do NOT seem to work. The test would continue run but it appears like it is trying to get that element but never succeeds so it eventually timed out based on the timeout setting the configuration file. For example. this is the log.
如果元素从DOM树中删除,那么处理测试时的用例可能会非常的频繁,例如,一个关闭并从页面中删除的模态当用户单击操作以关闭该模态元素或您想要删除的元素,使其不再存在于页面上的元素。因此,在测试中,只需要在DOM树中移除测试运行。
The use case of this can be quite frequent whenever you are dealing with testing if an element is removed from the DOM tree, for instance, a modal that is closed and removed from the page when user click actions that dismisses that modal element, or an element that you just want to "delete" so that it no longer exists on the page. So, in the test, you just want to continue the test run as soon as it is removed from DOM tree.
我通过量角器和网络驱动程序api进行了搜索,似乎没有api做这项工作。
I've searched through protractor and web driver api, and it seems there is no api that does this job.
推荐答案
不知道你在哪里得到 protractor.until
核心图书馆的一部分。这是你如何使用量角器:
not sure where you got protractor.until
from as that's not part of the core library. This is how you would do it with protractor:
var el = element(by.css('.your-css-class'));
return browser.wait(function() {
return el.isPresent().then(function(present) {
return !present;
})
});
一旦在(可能是量角器1.7),你可以这样做:
Once feat(expectedConditions) is in (probably protractor 1.7), you can do:
var EC = protractor.ExpectedConditions;
var el = element(by.css('.your-css-class'));
return browser.wait(EC.not(EC.presenceOf(el)));
这篇关于如何从DOM中删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!