导轨,将测试数据输入Capybara Systemtest中的条纹元素

发布于 2025-02-10 07:35:37 字数 1126 浏览 3 评论 0原文

我正在尝试使用Capybara/Minitest Systemtest测试结帐过程的条纹部分,但不知道如何将测试卡数据输入到条纹元素中。

这是输入字段之一:

<div class="CardNumberField-input-wrapper">
  <span class="InputContainer" data-max="4242 4242 4242 4242 4240">
    <input class="InputElement is-empty Input Input--empty" autocomplete="cc-number" autocorrect="off" spellcheck="false" type="tel" name="cardnumber" data-elements-stable-field-name="cardNumber" aria-label="Credit or debit card number" placeholder="Card number" aria-invalid="false" value=""></span></div>
  ..

我获得的最接近的是简单的:

fill_in('Card number', with: '4242424242424242')

这引起了:

Capybara::ElementNotFound: Unable to find field "Card number" that is not disabled

我怀疑,它可能不足以针对一个字段,但是您必须单击输入字段bevor。

当我尝试针对CSS类时:

find(class: 'CardNumberField-input-wrapper').fill_in('Card number', with: '4242424242424242')

我得到:

Capybara::ElementNotFound: Unable to find css nil with classes [CardNumberField-input-wrapper]

如何启用禁用字段?还有另一种方法吗?

I am trying to test the stripe part of a checkout process with a Capybara/Minitest Systemtest and do not know how to input the test card data into the stripe element.

This is one of the input fields:

<div class="CardNumberField-input-wrapper">
  <span class="InputContainer" data-max="4242 4242 4242 4242 4240">
    <input class="InputElement is-empty Input Input--empty" autocomplete="cc-number" autocorrect="off" spellcheck="false" type="tel" name="cardnumber" data-elements-stable-field-name="cardNumber" aria-label="Credit or debit card number" placeholder="Card number" aria-invalid="false" value=""></span></div>
  ..

The closest I got was with a simple:

fill_in('Card number', with: '4242424242424242')

which caused:

Capybara::ElementNotFound: Unable to find field "Card number" that is not disabled

I suspect, that it might not be enough to target a field, but that you have to click the input field bevor.

When I try to target the CSS class:

find(class: 'CardNumberField-input-wrapper').fill_in('Card number', with: '4242424242424242')

I get:

Capybara::ElementNotFound: Unable to find css nil with classes [CardNumberField-input-wrapper]

How can I enable the disabled field? Is there another way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被翻牌 2025-02-17 07:35:37

多亏了托马斯·范·霍尔德(Thomas Van Holder)在选择器上工作的提示,我得到了以下方式与XPath一起工作的。

within_frame(find(:xpath, '//*[@id="card-element"]/div/iframe')) do
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[1]/span[2]/div/div[2]/span/input').fill_in with: '................'
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[2]/span/span/input').fill_in with: '....'
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[3]/span/span/input').fill_in with: '...'
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[4]/span/span/input').fill_in with: '.....'
end

Thanks to Thomas Van Holder's hint to work on the selector, I got it working with Xpath in the following way.

within_frame(find(:xpath, '//*[@id="card-element"]/div/iframe')) do
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[1]/span[2]/div/div[2]/span/input').fill_in with: '................'
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[2]/span/span/input').fill_in with: '....'
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[3]/span/span/input').fill_in with: '...'
  find(:xpath, '//*[@id="root"]/form/div/div[2]/span[4]/span/span/input').fill_in with: '.....'
end
挖鼻大婶 2025-02-17 07:35:37

尝试按名称查找输入元素:

find('input["cardnumber"]')

Try finding the input element by name:

find('input["cardnumber"]')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文