2014-12-27 56 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