我想测试一个元素是否不存在于页面上。如何测量元素在Protractor页面上不存在?
我曾尝试使用下面的方法试了,但每次我得到一个错误:
方法:
expect(element(CastModule.PersonXpath).isDisplayed()).toEqual(false);
错误:失败:超时等待量角器 后的页面同步秒。请参阅https://github.com/angular/protractor/blob/master/docs/f ...
你推荐什么方法?
我想测试一个元素是否不存在于页面上。如何测量元素在Protractor页面上不存在?
我曾尝试使用下面的方法试了,但每次我得到一个错误:
方法:
expect(element(CastModule.PersonXpath).isDisplayed()).toEqual(false);
错误:失败:超时等待量角器 后的页面同步秒。请参阅https://github.com/angular/protractor/blob/master/docs/f ...
你推荐什么方法?
错误不应与检查元素缺失有关。请尝试以下操作:
var elm = element(CastModule.PersonXpath);
expect(browser.isElementPresent(elm)).toBe(false);
参见:
呀,测试不可见可苏茨基。您应该可以使用isPresent()
,这意味着在dom中,其中isDisplayed()
意味着它实际上可见,我认为这是您的问题。尝试...
expect(element(CastModule.PersonXpath).isPresent()).toEqual(false);
您可能还想将其分解为方法并使用Expected Condition。
很酷,谢谢。例如,如果我检查“x”分钟后元素不再显示,我需要使用什么? – user3188198
我设法找到了一个解决方案,使用量角器库。
var EC = protractor.ExpectedConditions; browser.wait(EC.invisibilityOf(element(by.xpath(CastModule.PersonXpath))), 5000).then(function() {
if (EC.invisibilityOf(element(by.xpath(x.LanguagesXpath)))) {
console.log("Persons module is not present - as expected for this scenario");
} else {
throw new Error("Element STILL present");
}
});
});
要检查的知名度(如果isDisplayed
或isPresent
不工作),只需使用:
if (!EC.invisibilityOf(ug.personXpath)) {
throw new Error("Partner logo is not displayed");
}
的错误看起来并不像它与正在显示的元素做。它看起来像是与页面同步。试着忽略了同步,然后等待角以上的预计有:
browser.ignoreSynchronization = true;
browser.waitForAngular();
expect(element(CastModule.PersonXpath).isDisplayed()).toEqual(false);
要使用元素的使用存在:
var elm = element(CastModule.PersonXpath);
elm.isPresent().then(function (present) {
if (present) {
element(CastModule.PersonXpath).then(function (labels) {
});
} else {
console.log('Element did not found');
}`enter code here`
Lulz @alecxe ......你在我之前提交! – Brine