简体   繁体   English

Selenium获取对象JS的属性

[英]Selenium getting the property of an object JS

The easiest way to explain my problem is to provide a picture of what I am trying to retrieve: 解释我的问题的最简单方法是提供一张我要检索的图片:

HTML属性

I am trying to get the source node of data which path's is ' data .source.displayName' using selenium but I can not simply retrieve this information. 我正在尝试使用硒来获取路径为' data .source.displayName'的数据的源节点,但是我不能简单地检索此信息。 I can retrieve information on the first layer of the HTML element such as 'textContent' but whenever I do id.getAttribute of an object it simply returns null. 我可以在HTML元素的第一层上检索信息,例如'textContent',但是每当我执行对象的id.getAttribute时,它只会返回null。 Some example code: 一些示例代码:

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*/

It's a little bit hard to tell what's exactly going on without more code, but your picture shows actually SVG tags. 如果没有更多代码,很难说清楚到底是什么情况,但是您的图片实际上显示了SVG标签。 It could be that the environment you are currently working in doesn't support that in the way you are trying to do it. 可能是您当前正在使用的环境不支持您尝试的方式。 Maybe this one helps: Read Attributes of SVG-Elements in HTML via JS . 也许这会有所帮助: 通过JS读取HTML中SVG元素的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM