In protractor 2.0, I am checking in a expect()
if one element is displayed. I expect a false, but the weird thing is that I get following error:
NoSuchElementError: No element found using locator: By.id(“userForm”)
My code is:
JavaScript
x
7
1
describe('closeModal', function() {
2
it('should close the alert that appears after registration.', function(){
3
element(by.id('closeAlertModalButton')).click();
4
expect(element(by.id('userForm')).isDisplayed()).toBeFalsy();
5
});
6
});
7
I understand that I get that error because element is not longer on the page (is what I want to confirm), but shouldn’t I get a false and not a error?
Advertisement
Answer
isDisplayed()
would check if an element is visible or not, but you need to check whether an element is present in DOM or not, use isElementPresent()
or isPresent()
:
JavaScript
1
3
1
expect(browser.isElementPresent(element(by.id('userForm')))).toBe(false);
2
expect(element(by.id('userForm')).isPresent()).toBe(false);
3
See also: