1

试图弄清楚如何使用 textarea 选择表单上的字段并指定类和 ID。不幸的是,我无法控制生成的 HTML,因为它是供应商产品。

示例 HTML:

<textarea class="text sr " id="arid_WIN_0_636875000" style="left: 402px; top: 0px; width: 261px; height: 21px;" rows="1" cols="20" wrap="off" arautoctt="400" arautocak="0" maxlen="255"></textarea>

我需要同时使用 ID 和类,因为 ID 用于多个点以及类,但是,我发现两者的组合是唯一的。

我试过做:

z = textarea(:class => "text sr ", :id  => "arid_WIN_0_636875000")

这回来了:

=> #<Watir::TextArea:0x272de17c located=false sel
>"arid_WIN_0_636875000", :tag_name=>"textarea"}>

尝试设置它并返回:

Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"text sr ", :id=>"arid_WIN_0_636875000", :tag_name=>"textarea"}
from C:/Ruby21/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.7.0/lib/watir-webdriver/elements/element.rb:507:in `assert_exists'
from C:/Ruby21/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.7.0/lib/watir-webdriver/user_editable.rb:32:in `clear'
from C:/Ruby21/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.7.0/lib/watir-webdriver/user_editable.rb:11:in `set'
from (irb):21:in `block in irb_binding'
from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/target_locator.rb:50:in `window'
from C:/Ruby21/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.7.0/lib/watir-webdriver/window.rb:193:in `use'
from (irb):20
from C:/Ruby21/bin/irb:11:in `<main>'

这是弹出窗口的 HTML:

<div class="DIVPopup shadow " id="popup_0" style="left: 495px; top: 161.5px; width: 930px; height: 673px; overflow: hidden; visibility: inherit; z-index: 100004;" arwindowid="0"><table class="DIVPopup ResizablePopup" id="DivTable" cellspacing="0" cellpadding="0"><tbody><tr class="DIVPopupTitleBar DIVDraggable"><td class="topleft">&nbsp;</td><td align="left" class="center" id="title_0" nowrap=""><div class="title">Name of form is here&nbsp;&nbsp;&nbsp;</div><button title="Close" class="Close  right" id="ardivpcl" onclick="var target=FindClickedPopup('0', event); if(target){ target.OnCancel();target.stopBubbling(event);return false;}" type="button"></button></td><td class="topright">&nbsp;</td></tr><tr><td class="DIVPopupBodyNoBorder DIVPopupBodyBorder" colspan="3"><iframe id="1433419427651P" src="/arsys/forms/vmpit-ermdy006/NameOfFormIsHere/Administrator/?cacheid=fa90df9&amp;format=html" frameborder="0" style="width: 100%; height: 652px;"></iframe></td></tr></tbody></table><b class="rndfooter" style="background-color: rgb(255, 255, 255);"><b class="rnd1" style="background-color: rgb(255, 255, 255);"></b><b class="rnd2" style="background-color: rgb(255, 255, 255);"></b><b class="rnd3"></b></b><div class="ResizeHandle  right" id="handle_0"></div></div>
4

2 回答 2

2

鉴于弹出窗口的 HTML,我猜它只是原始页面中的一个 div 元素,而不是它自己的浏览器窗口。访问弹出窗口应该是:

browser.div(:id => "popup_0")

也就是说,我没有在其中看到 textarea,这意味着它很可能在 iframe 元素中。iframes 必须明确告诉 Watir,这意味着找到你需要的 textarea:

browser.div(:id => "popup_0").iframe.textarea(:class => "text sr ", :id  => "arid_WIN_0_636875000")
于 2015-06-04T13:41:44.327 回答
0

我认为问题可能是你打错电话了。顺便说一句,不要混合你的哈希样式。选择更现代的风格而不是 hashrocket。试试这个...

get_a_better_name = textarea(class: "text sr ", id: "arid_WIN_0_636875000")

提示 - 使用像 rubocop ( https://github.com/bbatsov/rubocop ) 这样的代码 linter 可以帮助捕获这些错误。

于 2015-06-03T20:41:58.250 回答