Get Element Text with getText()
getText() retrieves the visible text of an element. It works on paragraphs, headings, buttons, spans, etc.
On the Text Messages page, you'll find several text elements:
id="plainText" - "A Plain Text"
id="boldText" - "A Bold Text" (inside a <strong> tag)
id="italicText" - "Italic Text" (inside an <em> tag)
HTML Structure:
<p id="plainText">A Plain Text</p>
<p id="boldText">
<strong>A Bold Text</strong>
</p>
<p id="italicText">
<em>Italic Text</em>
</p>
Note: getText() returns visible text including text inside child elements.
Task:
- Navigate to
https://testkru.com/Elements/TextMessages
- Print the text of each element listed above
Expected output:
Plain: A Plain Text
Bold: A Bold Text
Italic: Italic Text