2014-02-27 34 views
0

我正在使用以下代碼,以便通過右鍵單擊(在Selenium上下文菜單中)來顯示菜單。由dojo生成的嵌套div無法通過watir到達無法進行本地交互

# encoding: utf-8 
require 'watir-webdriver' 
b = Watir::Browser.new 


b.goto 'localhost:8080/swbadmin' 
b.text_field(:name => 'wb_username').set 'admin' 
b.text_field(:name => 'wb_password').set 'webbuilder' 
b.button(:text => 'Login').click 

a = b.div(:class => 'dijitTreeNodeContainer').div(:class => 'dijitTreeIsRoot').div(:class => 'dijitTreeRow').span(:class => 'dijitTreeContent') 
c= a.span(:text => 'tst') 
c.right_click 

問題是dijitTreeNodeContainer是由dojo製作的。所以我必須等到它加載所有的信息,我試圖使用Watir :: wait.until {span(:text =>'tst')。visible?}但它不起作用。 有了這個代碼,而行

c= a.span(:text => 'tst') 

與c.click,我能夠單擊默認TreeContent,但是當我嘗試用鼠標右鍵單擊或DOUBLE_CLICK,它拋出一個異常(..cannot瓶坯本地互動...) 這是HTML代碼

<div id="dijit_layout_AccordionPane_0" class="dijitContentPane dijitAccordionContainer-child dijitAccordionContainer-dijitContentPane dijitContentPaneSingleChild" selected="true" dojotype="dijit.layout.AccordionPane" widgetid="dijit_layout_AccordionPane_0" title="" style="width: 238px; height: 76.5px;"> 
<div url="/swbadmin/jsp/Tree.jsp?id=mtree" jsid="mtreeStore" dojotype="dojo.data.ItemFileWriteStore"></div> 
<div childrenattrs="children" rootid="root" store="mtreeStore" jsid="mtreeModel" dojotype="dijit.tree.ForestStoreModel"></div> 
<div id="mtree" class="dojoDndSource dojoDndTarget dojoDndContainer dijitTree" role="presentation" widgetid="mtree" tabindex="0" _dijitmenumtreemenu="1" style="width: 238px; height: 76.5px;"> 
<div class="dijitInline dijitTreeIndent" data-dojo-attach-point="indentDetector" style="position: absolute; top: -9999px"></div> 
<div class="dijitTreeExpando dijitTreeExpandoLoading" data-dojo-attach-point="rootLoadingIndicator" style="display: none;"></div> 
<div class="dijitTreeContainer" role="presentation" data-dojo-attach-point="containerNode" style="width: 100%;"> 
<div id="dijit__TreeNode_0" class="dijitTreeIsRoot dijitTreeNode dijitTreeNodeLoaded dijitLoaded" role="presentation" style="background-position: 0px 0px;" widgetid="dijit__TreeNode_0"> 
<div class="dijitTreeRow" role="presentation" data-dojo-attach-point="rowNode" style="padding-left: 0px; display: none;"> 
<div class="dijitTreeNodeContainer" style="height: auto;" role="tree" data-dojo-attach-point="containerNode" aria-expanded="true" aria-multiselectable="true"> 
<div id="dijit__TreeNode_3" class="dijitTreeIsRoot dijitTreeNode dijitTreeNodeNotLoaded dijitNotLoaded" role="presentation" style="background-position: 0px 0px;" widgetid="dijit__TreeNode_3"> 
<div class="dijitTreeRow dijitTreeRowSelected" role="presentation" data-dojo-attach-point="rowNode" title="" style="padding-left: 0px;"> 
<span class="dijitInline dijitTreeExpando dijitTreeExpandoClosed" role="presentation" data-dojo-attach-point="expandoNode"></span> 
<span class="dijitExpandoText" role="presentation" data-dojo-attach-point="expandoNodeText">+</span> 
<span class="dijitTreeContent" role="presentation" data-dojo-attach-point="contentNode"> 
<span class="dijitInline dijitIcon dijitTreeIcon swbIconWebSite" data-dojo-attach-point="iconNode" role="presentation"></span> 
<span class="dijitTreeLabel" aria-selected="true" tabindex="-1" role="treeitem" data-dojo-attach-point="labelNode,focusNode" aria-expanded="false">Demo</span> 
</span> 
</div> 
<div class="dijitTreeNodeContainer" style="display: none;" role="presentation" data-dojo-attach-point="containerNode"></div> 
</div> 
<div id="dijit__TreeNode_4" class="dijitTreeIsRoot dijitTreeNode dijitTreeNodeLoaded dijitLoaded" role="presentation" style="background-position: 0px 0px;" widgetid="dijit__TreeNode_4"> 
<div class="dijitTreeRow" role="presentation" data-dojo-attach-point="rowNode" title="" style="padding-left: 0px;"> 
<span class="dijitInline dijitTreeExpando dijitTreeExpandoClosed" role="presentation" data-dojo-attach-point="expandoNode"></span> 
<span class="dijitExpandoText" role="presentation" data-dojo-attach-point="expandoNodeText">+</span> 
<span class="dijitTreeContent" role="presentation" data-dojo-attach-point="contentNode"> 
<span class="dijitInline dijitIcon dijitTreeIcon swbIconWebSiteU" data-dojo-attach-point="iconNode" role="presentation"></span> 
<span class="dijitTreeLabel" aria-selected="false" tabindex="-1" role="treeitem" data-dojo-attach-point="labelNode,focusNode" aria-expanded="false">tst</span> 
</span> 
</div> 
<div class="dijitTreeNodeContainer" style="height: auto; display: none;" role="group" data-dojo-attach-point="containerNode"> 
</div> 
</div> 
</div> 
</div> 
</div> 
</div> 
</div> 
</div> 

回答

0

你沒有提到你正在使用的瀏覽器 - 它是火狐在Windows?在這種情況下,請嘗試產生Chrome代替:

b = Watir::Browser.new :chrome 

如果您必須堅持使用Firefox,請嘗試禁用本機事件。

profile = Selenium::WebDriver::Firefox::Profile.new 
profile.native_events = false 
b = Watir::Browser.new :firefox, :profile => profile 
+0

是的,我使用Firefox,我已經嘗試禁用本機事件,但沒有奏效。另一個問題是我無法通過文本'tst'到達第二個樹節點, – Yut