Rspec Target Font Awesome Icon Link

Is there a way for rspec to click on a specific font awesome icon? I am very new to rspec, so I apologize if this is a very simple question.

I tried click_link '.fa-envelope'

it but it looks like it is looking for the link name.

Any ideas?

EDIT:

Here's the html of the link I'm trying to click:

  <div class="col-sm-4 align-center">
    <a class="email-link" href="/contact"><i class="fa fa-envelope"></i></a>
  </div>

      

+3


source to share


3 answers


Assuming you are using capybara to use searchers instead:

find(".email-link").find(".fa-envelope").click

      



http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders

+2


source


You can also use the title attribute:

<div class="col-sm-4 align-center">
  <a class="email-link" href="/contact" title="Send email"><i class="fa fa-envelope"></i></a>
</div>

      

Then in the function specification, you can write:



click_link 'Send email'

      

Hope this helped!

+11


source


I realize this is an old question, but I came across this problem and none of the solutions provided in this thread and other SO threads worked for me.

This is a known bug in Capybara 2.1, mentioned in this thread . Here's a direct link to the suggested solution .

HTML snippet and solution to OP's problem.

HTML snippet:

  <div class="col-sm-4 align-center">
    <a class="email-link" href="/contact"><i class="fa fa-envelope"></i></a>
  </div>

      

Decision:

Capybara.page.execute_script %($('i.fa-envelope"').click())

      

PS: CSS crawlers won't work, so we'll have to use the method execute_script

until the bug is fixed.

+2


source







All Articles