Ruby - 尝试选择具有悬停下拉列表的选项卡

时间:2014-05-09 07:55:13

标签: ruby watir

如果我不清楚的话,我对所有这些都是新手如此道歉。

我正在为网站的管理部分创建自动化测试方案。

我正在尝试导航到标记为内容的标签,这也恰好是悬停下拉选项。

代码如下所示:

    <body class="dmundra" style="visibility: visible;">
<div class="imageBG"></div>
<div class="bannerBG"></div>
<div id="doc3" class="yui-t7">
<div id="hd">
<div id="menu">
<ul id="root" class="level1 horizontal">
<li class="level1 Active">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=34885ddb-3537-4a79-a02c-0550c5087d5c&p_p_id=EXT_21&p_p_action=0&&dm_rlout=1&r=1399625953307">
<div class="tabLeft">
<div class="navMenu-title">Home</div>
<div class="navMenu-subtitle">Tasks & Dashboard</div>
<div class="navMenu-arrow"> </div>
</div>
</a>
<span class="tabRight"></span>
<ul class="level2 dropdown" style="position: absolute; top: 90px; left: 10px; visibility: hidden;">
<li class="level2 dotCMS_EXT_21">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=34885ddb-3537-4a79-a02c-0550c5087d5c&p_p_id=EXT_21&p_p_action=0&&dm_rlout=1&r=1399625953308">
<span></span>
Workflow Tasks
</a>
</li>
<li class="level2 dotCMS_EXT_DASHBOARD">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=34885ddb-3537-4a79-a02c-0550c5087d5c&p_p_id=EXT_DASHBOARD&p_p_action=0&&dm_rlout=1&r=1399625953308">
<span></span>
Dashboard
</a>
</li>
</ul>
</li>
<li class="level1 ">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=931f0b26-92c1-420b-8fbf-e48089040921&p_p_id=EXT_BROWSER&p_p_action=0&&dm_rlout=1&r=1399625953308">
<div class="tabLeft">
<div class="navMenu-title">Site Editor</div>
<div class="navMenu-subtitle">Web & File Browser</div>
<div class="navMenu-arrow"> </div>
</div>
</a>
</li>
<li class="level1 ">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=71b8a1ca-37b6-4b6e-a43b-c7482f28db6c&p_p_id=EXT_11&p_p_action=0&&dm_rlout=1&r=1399625953308">
<div class="tabLeft">
<div class="navMenu-title">Content</div>
<div class="navMenu-subtitle">Manage your Site</div>
<div class="navMenu-arrow"> </div>
</div>
</a>
<span class="tabRight"></span>
<ul class="level2 dropdown" style="position: absolute; top: 90px; left: 266px; visibility: hidden;">
<li class="level2 dotCMS_EXT_11">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=71b8a1ca-37b6-4b6e-a43b-c7482f28db6c&p_p_id=EXT_11&p_p_action=0&&dm_rlout=1&r=1399625953308">
<span></span>
Content Search
</a>
</li>
<li class="level2 dotCMS_EXT_BROKEN_LINKS">
<a href="http://stag.web.est.wjec.co.uk/c/portal/layout?p_l_id=71b8a1ca-37b6-4b6e-a43b-c7482f28db6c&p_p_id=EXT_BROKEN_LINKS&p_p_action=0&&dm_rlout=1&r=1399625953308">
<span></span>
Link Checker
</a>
</li>
</ul>
</li>
</ul>
</div>

我尝试过按名称,链接和课程访问它,但无济于事。

这是我读过一个我认为类似的主题的最后一次尝试。

When(/^i select content tab$/) do
    while @browser.div(:id, 'navMenu-title').a(:text, "Content").exists? do
    @browser.div(:id, 'navMenu-title').a(:text, "Content").click 
end

1 个答案:

答案 0 :(得分:0)

navMenu-title是您在代码中编写的类而不是id。

尝试这样做,

When(/^i select content tab$/) do
  while @browser.div(:class, 'navMenu-title').link(:text,"Content").exists? do
  @browser.div(:class, 'navMenu-title').link(:text,"Content").click 
end

我没有测试它,但我认为它会起作用。

尝试使用,它会起作用

liObject=@browser.li(:class => "level1", :index => 2)
liObject.div(:class, 'navMenu-title').click;