[英]Selenium getting the property of an object JS
解釋我的問題的最簡單方法是提供一張我要檢索的圖片:
我正在嘗試使用硒來獲取路徑為' data .source.displayName'的數據的源節點,但是我不能簡單地檢索此信息。 我可以在HTML元素的第一層上檢索信息,例如'textContent',但是每當我執行對象的id.getAttribute時,它只會返回null。 一些示例代碼:
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標簽。 可能是您當前正在使用的環境不支持您嘗試的方式。 也許這會有所幫助: 通過JS讀取HTML中SVG元素的屬性 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.