iframe中的Watir和文本字段 [英] Watir and text field inside iframe

查看:100
本文介绍了iframe中的Watir和文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Watir将新文本设置为文本字段.文本字段位于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">

文本字段具有下一个Xpath:

The text field has next Xpath:

//*[@id="IDUserId"]

或CSS路径:

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

在使用HTML的情况下,它看起来像这样:

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"

返回:

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

推荐答案

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

您只想将Xpath作为最后的结果,因为它脆弱且复杂.我什至不确定CSS是否可以工作,因为我从未尝试过.

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.

请查看Željko的WATIR书

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

这篇关于iframe中的Watir和文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆