twalpole / apparition

Capybara driver for Chrome using CDP
MIT License
363 stars 46 forks source link

fill_in slower? #17

Closed will closed 5 years ago

will commented 5 years ago

Is there a way to get fill_in to type more slowly? I have a form that uses some javascript form Stripe to verify credit card checksums or whatever it does and that seems to be slow enough that numbers are skipped when filling in that field.

fill_in "cc-number", with: "4242424242424242"

image Notice the repeated 4s when the literal is all alternating.

When running in not-headless, it doesn't fail, I guess because actually rendering the input is slow enough, whereas in headless it can go faster.

In the meantime I've worked around this by making a helper that cheats by directly setting the value property, but I'm wondering if there is another way that would be "better"?

  def cheat_fill_in(id, opts)
    page.driver.evaluate_script "document.getElementById('#{id}').value = '#{opts[:with]}'"
  end
twalpole commented 5 years ago

@will Yes - Apparition supports a delay option when filling in text fields. You can do

fill_in "cc-number", with: "4242424242424242", fill_options: { delay: 0.1 }

to wait 0.1 seconds between each key press. If you have already found the element then you could also do

element = find('#cc-number')
...
element.set("4242424242424242", delay: 0.1)
will commented 5 years ago

Thank you!

sfcgeorge commented 5 years ago

Hah, I had exactly this issue down to the 4242424242424242 string. Thanks!