Capybara rejects text with "<" (lower than character)

72 views Asked by At

I have a spec to test if I'm able to show some different characters inside a given element. Say we have the element:

<p class="my-strange-characters-text">
  "Here they are: \" & ; ' > # <"
</p>

The problem is that, with Capybara's default driver it doesn't retrieve the "<" character.

In my spec, if I do:

first(".my-strange-characters-text").text

The output is

Here they are: \" & ; ' > # 

No "<" character! (nor whatever I insert after)

BUT, if i use :js => true, that will invoke the Poltergeist driver, it returns the text correctly.

I don't want to use :js => true on this specific text.

Obs:

I've tried '<', \< and other tricks to make it appear, but no success. Any hint?

1

There are 1 answers

0
Frederick Cheung On

In HTML, a literal < is written as &lt;. Ampersands must also be replaced with &amp;

Browsers try their best to interpret invalid HTML, which is probably why poltergeist (which under the hood is using WebKit) is able to guess at the text you wanted to insert.