2014-12-27 55 views
0

朋友。 我正在研究ruby使用watir在网站AliExpress.com上测试登录。我想自动填写表格https://login.aliexpress.com,但不幸的是我。该网站正在使用框架。 形式具有的html代码:Watir不能在框架中工作

<div id="login-content" class="form clr"> 
<dl> 
<dt class="fm-label"> 
<div class="fm-label-wrap clr"> 
<span id="login-id-label-extra" class="fm-label-extra"></span> 
<label for="fm-login-id">Account:</label> 
</div> 
</dt> 
<dd id="fm-login-id-wrap" class="fm-field"> 
<div class="fm-field-wrap"> 
<div id="account-check-loading" class="loading-mask"> 
<div class="loading-icon"></div> 
<div class="loading-mask-body"></div> 
</div> 
<input id="fm-login-id" class="fm-text" autocapitalize="off" autocorrect="off" autocomplete="off" value="" placeholder="Email address or member ID" tabindex="1" name="loginId"> 
</div> 

我的代码:(红宝石2.1.5-P273,IE11)

require 'watir' 
b = Watir::Browser.new 
b.goto "https://login.aliexpress.com" 
b.div(id:"expressbuyerlogin", class:"iframe-show").exist? # => true 
b.text_field(:name, "loginId").set "[email protected]" # => Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_name=>["text", "password", "textarea"], :name=>"loginId"} 
b.text_field(:name, "password").set "xxxxxxxxxxx" # => Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_name=>["text", "password", "textarea"], :name=>"password"} 

任何想法? 谢谢。

回答

0

将帧视为单独的浏览器上下文,因此您必须指定您所在的帧。(对于嵌套iframe,您需要指定每个帧直到达到所需的上下文)。在这种情况下,你的代码应该是这样的:

require 'watir' 
b = Watir::Browser.new 
b.goto "https://login.aliexpress.com" 
b.iframe(id: 'alibaba-login-box').text_field(name: "loginId").set "[email protected]" 
b.iframe(id: 'alibaba-login-box').text_field(name: "password").set "xxxxxxxxxxx" 
+0

非常感谢!脚本与Firefox完美配合,但IE 11(Windows 7sp1)有错误:WIN32OLERuntimeError :(在OLE方法文件中)OLE错误代码:80070005在 Pers2012 2014-12-28 07:32:37

+0

尝试使用此: '''require'watir' Watir.driver =:webdriver''' 或 '''require'watir-webdriver'''' – titusfortner 2014-12-28 17:45:47

+0

使用IEDriverServer_Win32 + require'watir-webdriver'解决了IE11的问题。所有的作品都很好。非常感谢。 – Pers2012 2014-12-29 16:26:34

0

请添加需要“的Watir-webdriver的” 此外,请确保您使用的是最新的“的Watir-webdriver的”版本和的Watir版本1.5.1.1145。

+0

使用IEDriverServer_Win32 + require'watir-webdriver'解决了IE11的问题。谢谢。 – Pers2012 2014-12-29 16:29:19