Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara expect an input placeholder that's within a div to have some text

I have a snippet that looks like this and I'm trying to run a test that expects the placeholder.

<div class="article_creator_isni form-group">
  <label class="control-label multi_value optional" for="article_creator_isni">Creator ISNI</label>
  <input type="text" name="article[creator_group][][creator_isni]" id="article_creator_group__creator_isni" class="article_creator_group form-control multi-text-field multi_value ubiquity_creator_isni" placeholder="Please enter the creator's ISNI, e.g. 0000 1234 5678 9101." data-field-name="ubiquity_creator_isni">
</div>

I've been able to get it to pass with

expect(page.find(".article_creator_isni input")['placeholder']).to eq 'Please enter the creator\'s ISNI, e.g. 0000 1234 5678 9101.'

Is there a better way to write the expect?

like image 334
Kirk Avatar asked Nov 18 '25 21:11

Kirk


1 Answers

That seems ok to me, you could be more specific by using the id perhaps though?

expect(find("#article_creator_group__creator_isni")["placeholder"]).to eq "Please enter the creator's ISNI, e.g. 0000 1234 5678 9101."
like image 144
J c Avatar answered Nov 21 '25 13:11

J c