Reputation: 37
I am on the last page of a checkout page. When I load the checkout page a split second later the fields will appear which will allow the user to enter credit card information. The credit card fields are as I understand injected by the credit card company into the page.
The code for payment section looks like this:
<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>
I am attempting to access the last couple of lines which is the "card_number" field so I can enter cc information in. Any idea how I can do this? I have tried the following snippet but get an error
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)
Upvotes: 1
Views: 347
Reputation: 5283
From the supplied HTML, it looks like that element is in an iframe
. You'll need to specify that:
b.iframe(:class => "lb-booking-payment-iframe payment_iframe-processed").text_field(:id => 'card_number').set '9999999999'
Upvotes: 2
Reputation: 44725
You cannot access fields within iframe directly same way as other fields, you need to access iframe's scope first:
b.iframe(class: "lb-booking-payment-iframe").text_field(id: 'card_number').set '999999999'
Upvotes: 0