<div class="player__AAtt"> <div> <play-js data-account="1234567890" data-id="32667_32797"> </play-js> </div> </div>
I want to get the values of data-account and data-id which are elements within play-js tag.
elemname = driver.find_elements_by_xpath('xpath.../div/play-js')
I tried like below, but I couldn’t get the value.
With javascript, I was able to import it with the code below.
var elems = document.querySelectorAll('.player__AAtt play-js'); console.log(elems[0].dataset.account) console.log(elems[0].dataset.dataid)
How can I get the value of an element within a tag rather than the tag itself?
Advertisement
Answer
You can use the .get_attribute()
method:
elemname = driver.find_elements_by_xpath('xpath.../div/play-js') elemname.get_attribute("data-account")