无法访问文本字段 - watir

时间:2015-12-17 22:31:23

标签: ruby watir watir-webdriver

我在结帐页面的最后一页。当我稍后加载结账页面时,会出现一些字段,允许用户输入信用卡信息。据我所知,信用卡领域由信用卡公司注入页面。

付款代码部分如下所示:

<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 个答案:

答案 0 :(得分:2)

从提供的HTML中,该元素看起来像iframe。您需要指定:

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

答案 1 :(得分:0)

您无法直接访问iframe中与其他字段相同的字段,您需要先访问iframe的范围:

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