I want to print the "data-tip" data here. but I couldn't do it anyway.
<div id="my_cash"><div data-number="3044519" data-positions="6" data-val="2044519" data-tip="2&nbsp;044&nbsp;519 cash" data-mobiletip="1&nbsp;973&nbsp;762 cash">2 M</div><div onclick="show_dialog('shop_treasures');"></div></div>
cash= site.find_element("xpath","//*\[@id='my_cash'\]/div\[1\]")
time.sleep(1)
print ('cash= ', cash.text)
outputs
"2m"
I tried
cash= site.find_element("xpath","//*\[@id='my_cash'\]/div\[1\]/@data-tip")
time.sleep(1)
print ('cash= ', cash.text)
I want to print the "data-tip" data here. but I couldn't do it anyway.
CodePudding user response:
data-tip
is not a text content but an attribute, so instead of cash.text
you should apply cash.get_attribute("data-tip")
here.
The entire code could be:
cash= site.find_element(By.XPATH,"//*[@id='my_cash']/div[1]")
print('cash= ', cash.get_attribute("data-tip"))