gpt4 book ai didi

javascript - Protractor ,使用 isDisplayed() 我得到 NoSuchElementError : No element found using locator

转载 作者:行者123 更新时间:2023-12-03 02:24:45 28 4
gpt4 key购买 nike

在 Protractor 2.0 中,我正在检查 expect() 是否显示一个元素。我预计会出现错误,但奇怪的是我收到以下错误:

NoSuchElementError: No element found using locator: By.id("userForm")

我的代码是:

describe('closeModal', function() {
it('should close the alert that appears after registration.', function(){
element(by.id('closeAlertModalButton')).click();
expect(element(by.id('userForm')).isDisplayed()).toBeFalsy();
});
});

我知道我收到该错误是因为元素不再在页面上(这是我想确认的),但我不应该得到一个 false 而不是错误吗?

最佳答案

isDisplayed() 会检查一个元素是否可见,但是你需要检查一个元素是否存在于 DOM 中,使用 isElementPresent()isPresent() :

expect(browser.isElementPresent(element(by.id('userForm')))).toBe(false);
expect(element(by.id('userForm')).isPresent()).toBe(false);

另请参阅:

关于javascript - Protractor ,使用 isDisplayed() 我得到 NoSuchElementError : No element found using locator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30099903/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com