0

我正在使用以下代码,以便通过右键单击(在 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 是由道场制作的。所以我必须等到它加载所有信息,我尝试使用 Watir::wait.until{ span(:text => 'tst').visible ?} 但它不起作用。使用此代码没有行

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

并且使用 c.click,我可以单击默认的 TreeContent,但是当我尝试使用右键单击或双击时,它会引发异常(..cannot preform native interaction...)这是 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>
4

1 回答 1

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
于 2014-02-28T17:06:58.573 回答