Jasmine 是否有任何方法可以验证并非每次都出现的动态弹出窗口
若弹出窗口出现,上面的代码在量角器jasmine框架中工作得很好,但当弹出窗口不出现并且脚本执行停止时,它会失败。Jasmine 是否有任何方法可以验证并非每次都出现的动态弹出窗口,jasmine,protractor,Jasmine,Protractor,若弹出窗口出现,上面的代码在量角器jasmine框架中工作得很好,但当弹出窗口不出现并且脚本执行停止时,它会失败。 只有当某些条件匹配时才会出现弹出窗口。您可以使用elementFinder方法isPresent()而不是browser方法来尝试此操作 var name = element(by.xpath("//p[contains(text(),'We will be adding this information')]")); if ( browser.isElementP
只有当某些条件匹配时才会出现弹出窗口。您可以使用elementFinder方法isPresent()而不是browser方法来尝试此操作
var name = element(by.xpath("//p[contains(text(),'We will be adding this information')]"));
if ( browser.isElementPresent(name)) {
try {
element(by.xpath("//button[@class='ok-btn']")).click();
} catch (error) {
console.log('Not able to click on duplicate pop-up '+error);
}
} else {
console.log('Fresh');
}
您好@DublinDev我已经尝试了您的代码,但是'element(by.xpath(//button[@class='ok-btn'])。单击();'总是执行。当弹出窗口未出现在代码上方时,同样的旧问题。但下面的解决方案对我有效``name.isPresent()。然后(函数(结果){if(结果){element(by.xpath)(“xpath”)。单击();}否则{console.log('Fresh');}});```谢谢:)@ebruyener
const name = element(by.xpath("//p[contains(text(),'We will be adding this information')]"));
if (name.isPresent()) {
try {
element(by.xpath("//button[@class='ok-btn']")).click();
} catch (error) {
console.log('Not able to click on duplicate pop-up '+error);
}
} else {
console.log('Fresh');
}