Alexander Stavonin
Alexander Stavonin

Reputation: 670

Watir and text field inside iframe

I'm trying to setup new text into a text field using Watir. The text field is placed inside iframe.

<div id="div_popup_layer" style="width: 100%; height: 100%;">
<div id="id_Login" class="ui-draggable" style="position:absolute;left:372.5px;top:279px;width:501px;height:274px;z-index:15">
<table id="popup_cont_id_Login" cellspacing="0" cellpadding="0" topmargine="0">
<tbody>
<tr>
<td align="left" valign="middle">
<iframe id="frame_id_Login" height="274px" frameborder="0" width="501px" allowtransparency="true" src="/sws.login/gnb/loginView.sws?basedURL=undefined&popupid=id_Login" tagtype="popup_iframe" name="frame_id_Login">

The text field has next Xpath:

//*[@id="IDUserId"]

Or CSS Path:

html body#POPUP_BODY table#loginBackground tbody tr td form#loginForm table tbody tr td table tbody tr td table tbody tr td div#userIDBlock table tbody tr td table tbody tr td#swsText_body_IDUserId_td.sws_text_normal_body div input#IDUserId.sws_text_input

And in case of HTML it looks like this:

<div><input type="text" value="" maxlength="63" style="width:142px; " class="sws_text_input" name="IDUserId" id="IDUserId" onfocus=" swsText_styleChangedFocus('IDUserId');" autocomplete="off" tagtype="text"></div>

I've checked a lot of variants without success. For example:

browser.frame(:id => "frame_id_Login").text_field(:name => "IDUserId").set "admin"

Returns:

/var/lib/gems/1.8/gems/watir-webdriver-0.5.3/lib/watir-webdriver/elements/frame.rb:9:in `locate': unable to locate frame/iframe using {:id=>"frame_id_Login"} (Watir::Exception::UnknownFrameException)

Could anyone help me with it? I need to put any text into the field.

Upvotes: 3

Views: 8621

Answers (4)

boulder_ruby
boulder_ruby

Reputation: 39695

Maybe watir has been updated since these answers were posted, but none of these frame methods worked for me. I was able to successfully use the iframe method, and interact with that just like any other object. Once the iframe object was selected, I could call on DOM elements after the iframe call successfully. Was only able to select the iframe object using its 'id' tag even though it had a 'name' attribute as well..

browser.text_field(:id => "handle").exists?
#=> false

browser.iframe(:id => "secureform").text_field(:id => "handle").exists?
#=> true

Upvotes: 3

cage
cage

Reputation: 103

Another working solution browser.frame(:id => "iFrameID").text_field(:id => /TextField/).set "data"

HTH

Upvotes: 0

Alexander Stavonin
Alexander Stavonin

Reputation: 670

The working solution is:

browser.frame(:index => 1).text_field(:index => 0).set "admin"

Now I'm trying to understand why :)

Upvotes: 1

adam reed
adam reed

Reputation: 2024

@browser.text_field(:id => "IDUserId").set "TEXT"
@browser.text_field(:name => "IDUserId").set "TEXT"
@browser.text_field(:class => "sws_text_input").set "TEXT"

Those will all work for a this text field as long as it is not contained in a frame, at which point you will need to identify it.

You only want to use Xpath as a last result, as it is fragile and complicated. I'm not even sure if CSS works as I've never tried it.

Please check out Željko's WATIR book or www.watir.com for basic locator methods.

Upvotes: 3

Related Questions