protractor - 如何解决量角器中 isDisplayed() 的承诺
问题描述
以下是我返回的代码:
TypeError:无法读取未定义的属性“then”
verifyElement(locator){
var text = element(by.xpath(locator)).isDisplayed()
text.then(function(result){
console.log("Element is displayed");
return true
},
function(error){
console.log("Element is not displayed");
return false;
}
)}
解决方案
试试下面的代码。Promise 与箭头函数配合得很好。
element(by.xpath(locator)).isDisplayed().then(status => {
if(status){
//code if element displayed
assert(true,'Element is displayed');
}else{
assert(false,'Element is not being displayed');
}
});
干杯!
推荐阅读
- javascript - WebDriver JavaScriptExecutor 没有点击按钮
- java - 如何使 java 中的按钮与 textField 对应?
- c# - 如何将同一供应商的所有datagridview数据插入sql数据库的一行
- python - Add a column from one pandas dataframe to another when both are indexed differently
- angularjs - 使用多个解析时 Angular UI 路由器抛出错误
- django - UrlGatewayLogin 未返回 HttpResponse 对象。它返回 None 而不是
- php - Atom PHP debug does not navigate to or highlights other files
- android - 无法启动 Gradle 守护程序。由于非 ASCII 字符,项目不会加载
- python - QuantLib-Python 无法检测到 QuantLib 安装和致命错误 C1083
- android - How to load webview in recyclerview?