How to wait for a page to load or element to be present when using Protractor for a non-Angular page

前端 未结 4 1554
耶瑟儿~
耶瑟儿~ 2021-02-09 16:32

I am new to Protractor. I think I have this down when dealing with an Angular page, but can\'t figure it out for a non-Angular page. Any help would be appreciated.



        
4条回答
  •  无人共我
    2021-02-09 17:22

    In protractor there are two types terms for on the page. isPresent ask if the element is exists on the page. isDisplayed asks if the element is visible. If you are waiting for a page to load you need to wait for isDisplayed, but that will error if it is not present, so wait for isPresent first. I use a function to wait for an element.

    function waitForElement(el, waitTimeoutMilliseconds){
        return browser.wait(function() { return el.isPresent(); }, waitTimeoutMilliseconds)
            .then(function(){
               return browser.wait(function() { return el.isDisplayed(); }, waitTimeoutMilliseconds);
            });
    }
    

    Then just call that function in your test.

    describe('Search', function() {
        it('should click Search button and wait for results', function() {
            var el = element(by.id('search'));
            waitForElement(el, 5000);
            el.click();
        });
    });
    

提交回复
热议问题