Capybara cannot fill Stripe Checkout.js fields

2019-05-27 11:31发布

问题:

I am having a difficult time testing Stripe's Checkout.js product with Capybara. The problem is Stripe has some tricky client side validation that fools Capybara's javascript driver, so when I tell Capybara to fill in a field, like this:

fill_in "card_number", with: "4242424242424242"

Stripe field only fills up oly the first three digits then it automatically puts a space after those digits, and that breaks Capybara badly.

How can I fix this?

回答1:

I don't know exactly but when i get into these situations i consider dropping directly into the browsers javascript, such as (in this case assuming jquery is present)

page.execute_script(%Q{ $('input#itsId').val('424242424242424242'); })