Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With capybara-webkit you can tell the driver to run any javascript you want within the context of the page, so you can write something custom to hack around the visibility issue: </p> <pre><code>script = "$('thelabel').toggle(); " # hide the label script &lt;&lt; "$('myfield').toggle();" # show your field page.driver.browser.execute_script(script) </code></pre> <p>This is pseudo-code, but you should be able to do something similar to make the field visible before you call <code>attach_file</code> on it.</p> <p>That said, every time (I at least) do something a little gross like this in my tests it is a good idea to take a quick moment and ask if it is the test or the interface that needs to be fixed. If you're happy with the interface, you should be able to use a small js snippet like the above to get the element visible for your test.</p> <h2>Update:</h2> <p>Support for this behavior has become more widespread and is now standardized in capybara, so you can just:</p> <pre><code>page.execute_script(script) </code></pre> <p>This shorter version should work with <a href="https://github.com/jnicklas/capybara" rel="noreferrer">capybara</a> 2.x and recent versions of <a href="https://github.com/thoughtbot/capybara-webkit" rel="noreferrer">capybara-webkit</a> or <a href="https://github.com/jonleighton/poltergeist" rel="noreferrer">poltergeist</a>, which is a lower-dependency alternative I'm using now.</p> <p>There is also a partner method, <code>evaluate_script</code>:</p> <pre><code>result = page.evaluate_script('4 + 4'); </code></pre> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload