Miles B
Miles B

Reputation: 129

How can Selenium Webdriver get text from mouseover element?

I am trying to scrape my discord server using selenium to search for messages and get the details of the message, specifically the date and time the messages were sent.

I have been able to get the time from the text contents of the message element, however the date is behind a mouseover hover tooltip (if you have used discord you might know what I mean).

I've tried to search for the way to get the text of the tooltip but none of the ways have worked/the solutions available were not about getting the text. i.e get_attribute('title') doesn't work.

For reference the element of the tooltip is:

<span class="latin12CompactTimeStamp-38a8OU timestamp-3ZCmNB timestampVisibleOnHover-2bQeI4 alt-1uNpEt"><span aria-label="15:03"><i class="separator-2nZzUB" aria-hidden="true">[</i>15:03<i class="separator-2nZzUB" aria-hidden="true">] </i></span></span>

I can edit and include my python code but I don't think it would help to explain much.

enter image description here

url is in the form (https://discord.com/channels/{guild ID}/{channel ID}/{message ID}) to my knowledge...

Upvotes: 0

Views: 1195

Answers (1)

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

The date is in the aria-label in the span child class

elem=driver.find_element_by_xpath("//span[starts-with(@class,'latin12CompactTimeStamp')]/span[1]")

Then use either

print(elem.get_attribute('aria-label'))
print(elem.text)

Upvotes: 1

Related Questions