# Assert a Get Text with \<strong\> in the HTML markup

**URL:** <https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226>\
**Category:** Browser\
**Created:** [30 January 2023 20:21 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226 "2023-01-30T20:21:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![northernHemisphere](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@northernHemisphere](https://forum.robotframework.org/u/northernHemisphere)\
**Post date:** [30 January 2023 20:21 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/1 "2023-01-30T20:21:28Z")

</div>

I am trying to assert contents of a

 tag in a test case.

HTML fragment contains

```plaintext
<div id="result"><strong>42</strong> results</div>

```

In my test case, this assertion fails because there are some invisible characters before and after “42”.

```
Get Text	id=result	==	42 results

```

What is the way to do this assertion?

---

<div class="post-metadata">

**Author:** ![northernHemisphere](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@northernHemisphere](https://forum.robotframework.org/u/northernHemisphere)\
**Post date:** [30 January 2023 20:33 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/4 "2023-01-30T20:33:48Z")

</div>

The markdown engine is eating my HTML fragment.

`<div id="result"><strong>42</strong> results</div>`

---

<div class="post-metadata">

**Author:** ![a-mamlouk](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/a-mamlouk/32/2271_2.png) [@a-mamlouk](https://forum.robotframework.org/u/a-mamlouk)\
**Post date:** [30 January 2023 21:24 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/5 "2023-01-30T21:24:04Z")

</div>

i remember i wrote this code a while ago, hope it helps

```plaintext
 Count_Test

    ${alllinkscount}= get element count xpath://a
    log to console ${alllinkscount}
# ${alllinkscount}= Evaluate ${alllinkscount} + 1
# log to console \r${alllinkscount}
    @{linkItems} create list
    FOR ${i} IN RANGE 1 ${alllinkscount}+1
        ${linktext}= get text xpath:(//a)[${i}]
        log to console \r[${i}], ${linktext}
    END

```

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [30 January 2023 22:02 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/6 "2023-01-30T22:02:30Z")

</div>

Hi @northernHemisphere

I tried your html snipped and the `<strong>` does not influence the `Get Text` .

What sometimes is an issue is a `&nbsp;` (no-break space) which is a different character than a normal space.  
Often Web developers use these to ensure that the spaces does not lead to a line break.

Maybe you can post the error message you get?

Ps: Three “Back Ticks” ````` before and after the preformatted code does the trick here in the forum.

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [30 January 2023 22:21 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/7 "2023-01-30T22:21:14Z")

</div>

Now maybe as a last resort:  
you can log the “non printable” characters like this:

```plaintext

    ${text} = Get Text id=result
    ${escaped} = Evaluate [c if c in string.printable else r'\x{0:02x}'.format(ord(c)) for c in $text] modules=string
    Log To Console ${escaped}

```

That weird python expression escapes non printable characters.  
then you can figure out what there is.

---

<div class="post-metadata">

**Author:** ![northernHemisphere](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@northernHemisphere](https://forum.robotframework.org/u/northernHemisphere)\
**Post date:** [31 January 2023 01:48 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/8 "2023-01-31T01:48:08Z")

</div>

I thought I’d jump to last resort to get an idea of what is in the string…

`['x2068', '1', '7', 'x2069', ' ', 'r', 'e', 's', 'u', 'l', 't', 's']`

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [31 January 2023 08:01 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/9 "2023-01-31T08:01:14Z")

</div>

it looks like that \u2068 is a start of strong.

See [⁨ - First Strong Isolate: U+2068 - Unicode Character Table](https://unicode-table.com/en/2068/)

But i doubt that this has anything to do with the html `<strong>` .  
I would guess that the content has additionally these two start and end characters.

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [31 January 2023 08:27 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/10 "2023-01-31T08:27:01Z")

</div>

So i tested a bit more and you can in JavaScript send these unicode characters to the element like this.

```python
Evaluate JavaScript id=result e => e.innerHTML = "<strong>\u206842\u2069</strong> result"

```

without the `<strong>` it is not rendered as strong on the page.

You can however replace these special characters when reading it with

```python
Get Text id=result validate re.sub('[\u2068\u2069]', '', value) == '42 result'

```

Or just return it with

```python
Get Text id=result evaluate re.sub('[\u2068\u2069]', '', value)

```

---

<div class="post-metadata">

**Author:** ![northernHemisphere](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@northernHemisphere](https://forum.robotframework.org/u/northernHemisphere)\
**Post date:** [31 January 2023 13:36 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/11 "2023-01-31T13:36:33Z")

</div>

Thanks Rene.

Well you learn something everyday. Our internationalization library is putting these Unicode characters in by default to support display of bi-directional text. The HTML fragment I am testing is generated through that library (in our case to make sure pluralization of the word “result” matches the number of results) so it is putting in these Unicode characters. Turns out this is great as we will be working in right to left languages in the future.

The FSI 0x2068 and PDI 0x2069 are Unicode characters to help with the correct display of bi-directional text. For the benefit of future readers of this chat, see [Unicode Isolation · projectfluent/fluent.js Wiki · GitHub](https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation).

Now that I know what is going on, I can design my test cases.

Regards.

---

<div class="post-metadata">

**Author:** ![northernHemisphere](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@northernHemisphere](https://forum.robotframework.org/u/northernHemisphere)\
**Post date:** [31 January 2023 14:46 UTC](https://forum.robotframework.org/t/assert-a-get-text-with-strong-in-the-html-markup/5226/12 "2023-01-31T14:46:49Z")

</div>

Because the FSI and PDI characters are there, I think I’ll write the test to explicitly check for them.  
` Get Text id=result \u206842\u2069 results`

The alternative would be to strip them out, which would also get the test passing.
