首页 > 解决方案 > 如何通过 Splinter 填写 Stripe Element 表单?

问题描述

这些是条纹元素:https ://stripe.com/docs/stripe-js/elements/quickstart 。

我想使用 Splinter 测试它们,但不能在保留字符顺序的同时填写输入。

标签: pythonseleniumintegration-testingstripe-paymentssplinter

解决方案


def fill_in_stripe_input(browser, iframe_name, input_name, value):
    # every Stripe Element is in a separate iframe
    with browser.get_iframe(iframe_name) as iframe:
        # get the internal Selenium element.
        selenium_input = iframe.find_by_css('input[name=' + input_name + ']').first._element
        # just send_keys('424242...') doesn't work, because order of characters may get mixed up
        for character in value:
            selenium_input.send_keys(character)

from splinter import Browser
browser = Browser('chrome', executable_path='/usr/local/bin/chromedriver')
fill_in_stripe_input(browser, iframe_name='__privateStripeFrame3', input_name='cardnumber', value='4242424242424242')
fill_in_stripe_input(browser, iframe_name='__privateStripeFrame4', input_name='exp-date', value='0320')
fill_in_stripe_input(browser, iframe_name='__privateStripeFrame5', input_name='cvc', value='999')

推荐阅读