0

Kind of a strange one, but in my views I have a tick (✔) and a cross (×) used as links (in lieu of images). Is there any way of finding these elements and testing them using RSpec and Capybara-webkit, or should I try and target say the title attribute instead and ignore this route?

My test in question looks like this:

context "casting a vote", js: true do
  before do
    sign_in user
    click_link '✔'
    sleep 0.2
  end

  it { should have_content("Vote cast!") }
end

The failure message I get is (predictably):

Failure/Error: click_link "raw('✔')"
Capybara::ElementNotFound:
Unable to find link "raw('✔')"

Thanks in advance for your help.

Alex Lynham
  • 1,318
  • 2
  • 11
  • 29
  • 4
    Check out http://stackoverflow.com/questions/11331060/international-chars-using-rspec-with-ruby-on-rails. If you include `# encoding: UTF-8` at the top of your spec file, you can just paste the tick or cross character right into your test with `click_link '✔'`. – cschroed Dec 02 '13 at 21:53
  • Amazing, thanks! Just makes it that bit more obvious than `page.find(:css, '#vote_link').click`! – Alex Lynham Dec 02 '13 at 22:04

1 Answers1

-1

Capybara doesn't see the HTML, it runs thru the DOM, which then sees the actual values those things encode. You must send the raw code as a UTF-{8,16} string containing the code point itself.

Most languages would present an HTML '✔' as "\u10004", so try that.

Phlip
  • 5,253
  • 5
  • 32
  • 48