verify that element disappear in protractor

柔情痞子 提交于 2019-12-04 12:56:56

You can use a custom waitAbsent() helper function that actively waits for an element to disappear either by becoming invisible or by not being present.

That helper waits up to specTimeoutMs ignoring useless webdriver errors like StaleElementError.

Usage: add require('./waitAbsent.js'); in your onPrepare block or file.

Example to wait for the modal to disappear:

expect($('.modal-backdrop.in').waitAbsent()).toBeTruthy();

Protractor's ExpectedConditions is the recommended way to do this now. You can use it in conjuction with browser.wait to create the wait condition for various states, among them invisibilityOf (if being hidden) or stalenessOf (if being removed from the DOM) an element.

browser.wait( EC.invisibilityOf( $('#selector') ), 5000 );

If the element is present on the page already, you can get down and dirty with callbacks :D , taking advantage of the fact that browser.wait() polls the page until the function passed to it evaluates to true.

browser.wait(function()
    {
        return browser.isElementPresent(by.repeater('recentName in recentNames').row(0)) //if element is already present, this line will evaluate to true
               .then(function(presenceOfElement) {return !presenceOfElement}); // this modifies the previous line so that it evaluates to false until the element is no longer present. 
    }, 10000);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!