watir无法访问由dojo创建的嵌套div无法执行本机交互

时间:2014-02-27 19:26:47

标签: dojo watir native-methods

我正在使用以下代码,以便右键单击显示菜单(在Selenium上下文菜单中)。

# 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时,它会抛出一个异常(..无法执行本机交互......) 这是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>

1 个答案:

答案 0 :(得分:0)

你没有提到你正在使用哪种浏览器 - 它是Windows上的Firefox吗?在这种情况下,请尝试生成Chrome:

b = Watir::Browser.new :chrome

如果你必须坚持使用Firefox,请尝试禁用原生事件。

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