Home > database >  i want python xpath data-tip print
i want python xpath data-tip print

Time:01-01

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&amp;nbsp;044&amp;nbsp;519 cash" data-mobiletip="1&amp;nbsp;973&amp;nbsp;762 cash">2&nbsp;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"))
  • Related