如何打印元素的值?

时间:2015-04-09 16:02:32

标签: angularjs protractor

我想将一个元素的文本值打印到控制台以进行调试。我有:

var result = element(by.model('vm.firstName')).getAttribute('value');
console.log('first name is: ' + result.getInnerHtml() + result.getOuterHtml() + result.getText() + "" + result.getId() + Object.keys(result));
expect(result).toBe('Colin');

期望过去了。日志没有给我"科林"如我所愿:

  

第一个名称是:[object Object] [object Object] [object Object] [object Object] ptor_,parentElementArrayFinder,然后是elementArrayFinder_,click,sendKeys,getTagName,getCssValue,getAttribute,getText,getSize,getLocation,isEnabled,isSelected ,提交,明确,isDisplayed,getOuterHtml,getInnerHtml,的getId,getRawId

如何才能显示名称而不是[object Object]?

1 个答案:

答案 0 :(得分:2)

当您尝试记录结果时,它仍然是一个未解决的承诺。请尝试以下方法:

var result = element(by.model('vm.firstName')).getAttribute('value');
//the .then statement will only execute once the promise has been resolved.
result.then(function(foo){
    console.log('first name is: ' + foo.getInnerHtml() + foo.getOuterHtml() + result.getText() + "" + foo.getId() + Object.keys(foo));
});