Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Choose by clicking label if input is hidden #668

Closed
lpender opened this issue Sep 17, 2014 · 2 comments
Closed

Choose by clicking label if input is hidden #668

lpender opened this issue Sep 17, 2014 · 2 comments

Comments

@lpender
Copy link

lpender commented Sep 17, 2014

Hi!

I'm trying to choose a hidden radio input by it's label with Capybara Webkit, but I'm getting Capybara::Webkit::ClickFailed: Failed to find position for element ... because it is not visible.

Here is a simple case for reproduction:

  <form>
    <input id="one" type="radio" name="form"/>
    <label for="one">Click me!</label>
    <input id="two" type="radio" name="form"/>
    <label for="two">Click me!</label>
  </form>

  <style>
    input {
      display: none;
    }
    input:checked + label {
      color:blue;
    }
  </style>

The spec would have a line something like:

choose 'one'

Would be great to get this working! No issues with vanilla Capybara.

Thanks!
-Lee

@lpender lpender changed the title Click on label if input is hidden Choose by label if input is hidden Sep 17, 2014
@lpender lpender changed the title Choose by label if input is hidden Choose by clicking label if input is hidden Sep 17, 2014
@mhoran
Copy link
Collaborator

mhoran commented Sep 18, 2014

Hey @lpender. There are a couple of things going on here. choose 'one' will still try to click the button. Providing the label text is an alternative, but in this case it's duplicated, and ultimately this will still end up with a click on the button itself. Instead, you can click on the label. In your case, find('label[for=two]').click will choose the hidden button.

@gregblass
Copy link

@mhoran A giant thank you for this sir! Wasted so much time before I finally found this.

s4na added a commit to s4na/twi-note that referenced this issue Feb 1, 2020
Test failed because tab (label) could not be clicked.

I referred to the site.
thoughtbot/capybara-webkit#668

Add click processing of label to test.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants