我需要在初始選擇器之后提取一個屬性“子元素”。
我使用這個語法作為選擇器:
${first_video}= Get WebElement xpath:(//div[contains(@data-store, 'videoID')])[1]
這正確地給了我這個單一元素部分:
<div data-store="{"videoID":"1234","playerFormat":"inline","playerOrigin":"video_home","external_log_id":null,"external_log_type":null,"playerSuborigin":"entry_point",
"useOzLive":false,"playOnClick":true,
"videoScrollUseLowThrottleRate":true,"playInFullScreen":false,"type":"video","src":"https:\/\/video.test.com\/v\/a\/123_n.mp","width":320,"height":180,
"videoURL":"https:\/\/www.test.com\/test\/videos\/12345\/","disableLogging":false}" data-sigil="Video">
</div>
我的目標是獲取 VideoURL 屬性。
我試過
${first_video_link}= Call Method ${first_video} value_of_css_property data-store.videoURL
但它給了我空輸出。有沒有我遺漏的特定語法?
非常感謝
uj5u.com熱心網友回復:
獲取data-store屬性的值:
${val}= Get Element Attribute ${your locator}
它似乎是一個正確的 json,因此將其轉換為 python 字典,然后只需訪問其鍵:
${as json}= Evaluate json.loads("""${val}""") json
Log To Console The videoURL is ${as json['videoURL']}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/345998.html
