'How I can get HTML tags where located some text

I have some text, like message

I have a method who search this last message:

def get_message_text(self):
    return self.get_elements(f"//*[@data-qa='Paragraph-message-text']")[-1].text

this text in HTML looks like this:

<h1><strong><em>message</em></strong></h1>

what the method will look like, which output:

em, strong, h1



Solution 1:[1]

Once you have the web element all that you need to get it's tag name(s) is
String tag = element.getTagName();
In case the element has several tags you will have to split tag names from the tag string.
My code syntax is in Java however it's quite similar to Python

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prophet