JavaScript
x
7
1
<div class="player__AAtt">
2
<div>
3
<play-js data-account="1234567890" data-id="32667_32797">
4
</play-js>
5
</div>
6
</div>
7
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.
JavaScript
1
4
1
var elems = document.querySelectorAll('.player__AAtt play-js');
2
console.log(elems[0].dataset.account)
3
console.log(elems[0].dataset.dataid)
4
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:
JavaScript
1
4
1
elemname = driver.find_elements_by_xpath('xpath.../div/play-js')
2
3
elemname.get_attribute("data-account")
4