Protractor Check if Element Does Not Exist

后端 未结 6 2024
长情又很酷
长情又很酷 2021-02-05 02:56

I have a setting in my angular based website that turns a dropdown on and off. If it is off, then it does not show on the main page.

With Protractor, I need to check to

6条回答
  •  -上瘾入骨i
    2021-02-05 03:01

    none of these answers which include count() worked for me;

    the typeof $$('.selector').count() is 'object'

    you have to use the promise to pull the count value out like this.

    const nameSelector = '[data-automation="name-input"]';
    const nameInputIsDisplayed = () => {
        return $$(nameSelector).count()
            .then(count => count !== 0)
    }
    it('should not be displayed', () => {
        nameInputIsDisplayed().then(isDisplayed => {
            expect(isDisplayed).toBeFalsy()
        })
    })
    

提交回复
热议问题