我将尝试测试页面上是否存在某个元素。
我已经尝试使用以下方法,但每次都会出现错误:
方法:
expect(element(CastModule.PersonXpath).isDisplayed()).toEqual(false);
错误:失败:等待Protractor与页面同步超时秒。请参见https://github.com/angular/protractor/blob/master/docs/f ...
你推荐什么方法?
我将尝试测试页面上是否存在某个元素。
我已经尝试使用以下方法,但每次都会出现错误:
方法:
expect(element(CastModule.PersonXpath).isDisplayed()).toEqual(false);
错误:失败:等待Protractor与页面同步超时秒。请参见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);
您可能也想将此分解为一个方法,并使用预期条件。
为了检查可见性(如果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);
browser.wait(() => {
return element(by.className("claasName")).isDisplayed()
.then(
(hasDisplayed) => {
console.log("Has displayed: "+ hasDisplayed);
return hasDisplayed === false;
}
);
}, 5000)
.then(
() => {
return true;
},
() => {
return false;
}
)
我成功找到了一个解决方案,使用了protractor库。
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");
}
});
});
使用元素存在性,请使用:
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`
expect(elem.isNull===undefined).to.be.equal(true);