2015-12-17 62 views
1

我在結賬頁面的最後一頁。當我稍後加載結賬頁面時,將顯示允許用戶輸入信用卡信息的字段。據我所知,信用卡領域是由信用卡公司將其注入頁面。無法訪問文本字段 - watir

支付部分的代碼如下所示:

<div id="block-system-main" class="block block-system block-main block-system-main even block-without-title"> 
<div class="content clearfix"> 
<form id="lb-booking-booking-alt-payment" class="booking-form jquery-once-1-processed" accept-charset="UTF-8" method="post" action="/booking/payment"> 
<div> 
<div id="lb-card-options"> 
<fieldset id="edit-payment-detail" class="form-wrapper"> 
<legend> 
<div class="fieldset-wrapper"> 
<div id="edit-payment-details-amount-to-pay" class="form-item form-type-yachts-item"> 
<div id="edit-payment-details-wrapper-payment-iframe" class="lb-booking-payment-iframe-wrapper form-wrapper"> 
<iframe class="lb-booking-payment-iframe payment_iframe-processed" width="100%" src="https://testing.datapayment.com/hps/?HPS_SessionID=0c2181c579-d532a6-4217a-929a-e59562af8474ea09" style="height: 388px;"> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html class="mti-inactive" lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<body leftmargin="0" topmargin="0"> 
<form class="payment-form" autocomplete="off" method="post" action="?"> 
<div class="gateway-form clearfix three-column-with-button"> 
<div class="form-fields form-wrapper clearfix"> 
<div class="form-item form-type-textfield"> 
<label for="card_number"> 
<input id="card_number" class="form-text required" type="text" maxlength="23" size="26" name="card_number"> 
</div> 

我試圖訪問的最後幾行這是「CARD_NUMBER」字段,所以我可以在輸入CC信息的任何想法如何,我可以做這個?我曾嘗試下面的代碼片段,但得到一個錯誤

b.text_field(:id => 'card_number').set '9999999999' 

unable to locate element, using {:id=>"card_number", :tag_name=>"input or textarea", :type=>"(any text type)"} (Watir::Exception::UnknownObjectException) 

回答

2

從提供的HTML,它看起來像元素在iframe。您需要指定:

b.iframe(:class => "lb-booking-payment-iframe payment_iframe-processed").text_field(:id => 'card_number').set '9999999999' 
0

您不能訪問iframe的直接相同的方式中的字段,如其他領域,你需要先訪問iframe的範圍:

b.iframe(class: "lb-booking-payment-iframe").text_field(id: 'card_number').set '999999999' 
+0

這會失敗,因爲它不是完整的類ID。您可以使用/ lb-booking-payment-ifream /。 –