我有一个如下页面代码。有一个项目列表。如何从以下项目中获取测试,应用程序,成功,错误的值?请帮忙。我正在尝试将此数据写入文件,但它获取[object,Object]
<div _ngcontent-c5="" class="grid-container">
<div _ngcontent-c5="" class="grid-x">
<div _ngcontent-c5="" class="small-12 medium-12 large-6 cell">Test:</div>
<div _ngcontent-c5="" class="small-12 medium-12 large-6 cell">
<!--bindings={
"ng-reflect-ng-if": "true"
}--><span _ngcontent-c5="" class="success">It works</span>
<!--bindings={
"ng-reflect-ng-if": "false"
}-->
<!--bindings={
"ng-reflect-ng-if": "false"
}-->
</div>
</div>
<div _ngcontent-c5="" class="grid-x">
<div _ngcontent-c5="" class="small-12 medium-12 large-6 cell">Application:</div>
<div _ngcontent-c5="" class="small-12 medium-12 large-6 cell">
<!--bindings={
"ng-reflect-ng-if": "false"
}-->
<!--bindings={
"ng-reflect-ng-if": "false"
}-->
<!--bindings={
"ng-reflect-ng-if": "true"
}--><span _ngcontent-c5="" class="error">Error</span>
</div>
</div>
我的代码:
it('save to file', () => {
var fs = require('fs');
var area = element.all(by.css('.div.grid-container'));
var outputFileName = 'Output.json';
fs.writeFile(outputFileName, area, function(err){
if(err){
console.log(err);
}
else{
console.log("JSON saved to " + outputFileName);
}
});
});
答案 0 :(得分:0)
您可以尝试JSON.stringify(area)
将对象转换为JSON字符串,然后再尝试将其保存到文件中。