我正在嘗試使用 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]
如何啟用禁用的欄位?還有另一種方法嗎?
uj5u.com熱心網友回復:
嘗試按名稱查找輸入元素:
find('input["cardnumber"]')
uj5u.com熱心網友回復:
感謝 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/497367.html
上一篇:在ActiveStorage自定義分析器中獲取“Vips::ErrorException:VipsJpeg:outoforderreadatline1440”
