Watir and text field inside iframe

回眸只為那壹抹淺笑 提交于 2019-12-09 03:43:33

问题


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.


回答1:


@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.




回答2:


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



回答3:


The working solution is:

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

Now I'm trying to understand why :)




回答4:


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

HTH



来源:https://stackoverflow.com/questions/9560320/watir-and-text-field-inside-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!