Test Stripe.js Elements with Capybara

To access and test Stripe.js Element objects with Capybara, try the following:

card_frame = page.evaluate_script("$(\"iframe[src*='fieldName']\").attr(\"name\")")
within_frame card_frame do
  find(".InputElement").set("value")
end

Where fieldName is the name of the Stripe.js Element, for example ‘cardNumber’, and the value is whatever you would like to set the field value to (e.g. 4242 4242 4242 4242)

Note, you may need to wait for the Stripe elements to load, depending on your implementation.

Leave a Reply

Your email address will not be published. Required fields are marked *