Javascript Selenium获取对象JS的属性
解释我的问题的最简单方法是提供我试图检索的内容的图片: 我正在尝试使用selenium获取data的源节点,其路径是“data.source.displayName”,但我无法简单地检索此信息。我可以检索HTML元素第一层的信息,如“textContent”,但每当我检索对象的id.getAttribute时,它只返回null。一些示例代码:Javascript Selenium获取对象JS的属性,javascript,selenium,object,properties,getattribute,Javascript,Selenium,Object,Properties,Getattribute,解释我的问题的最简单方法是提供我试图检索的内容的图片: 我正在尝试使用selenium获取data的源节点,其路径是“data.source.displayName”,但我无法简单地检索此信息。我可以检索HTML元素第一层的信息,如“textContent”,但每当我检索对象的id.getAttribute时,它只返回null。一些示例代码: var data = identity.getAttribute('__data__.source.displayName');
var data = identity.getAttribute('__data__.source.displayName');
data.then(function(classes){
console.log(classes);
}); /*this will print out null*/
var data = identity.getAttribute('textContent');
data.then(function(classes){
console.log(classes);
}); /* this prints out "node_15 → node_20" and works correctly*/
如果没有更多的代码,就有点难以判断到底发生了什么,但是您的图片实际上显示了SVG标记。可能是您当前工作的环境不支持您尝试的方式。也许这个有帮助