我已经尝试了大约 2 天的时间在这里的论坛和谷歌群组中搜索,但我发现的所有内容都没有奏效。基本上,顶部导航菜单被放入以下 HTML:
<div id="topNav">
<div id="headerLogo">
<div id="mainNav">
<ul id="nav">
<li id="navTab01" class="manageUsers">
<a class="mainNavItem" title="Manage Users And Groups" href="#"> </a>
<ul class="dropdown" style="display: none;">
</li>
<li id="navTab02" class="manageContent">
<a class="mainNavItem current" title="Manage Content" href="#"> </a>
<ul class="dropdown" style="display: none;">
<li class="manageSubRegions">
<li class="manageBusinessDirectoryEntries">
<a class="dropdownItemHasFlyout current" href="/BusinessDirectoryEntry"> Business Directory</a>
<ul class="flyout" style="display: none; left: 224px;">
</li>
<li>
</ul>
</li>
<li id="navTab03" class="manageFinancials">
<li id="navTab04" class="runReports">
</ul>
</div>
</div>
我要操作的菜单项是 navTab002,它具有以下扩展的 HTML:
<li id="navTab02" class="manageContent">
<a class="mainNavItem current" title="Manage Content" href="#"> </a>
<ul class="dropdown" style="display: none;">
<li class="manageSubRegions">
<a class="current" href="/SubRegion"> Regions</a>
</li>
<li class="manageBusinessDirectoryEntries">
<a class="dropdownItemHasFlyout current" href="/BusinessDirectoryEntry"> Business Directory</a>
<ul class="flyout" style="display: none; left: 224px;">
<li class="businessDirectoryEntryQuickAdd">
<a class="current" href="/BusinessDirectoryEntry/QuickAdd"> Quick Add</a>
</li>
<li class="manageBusinessCustomListings">
<a class="current" href="/BusinessDirectoryCustomListing"> Sectors</a>
</li>
<li class="manageBusinessDirectoryProfileTypes">
<a class="current" href="/BusinessDirectoryProfileType"> Profile Types</a>
</li>
<li class="manageBusinessDirectoryPrivateTypes">
<a class="current" href="/BusinessDirectoryPrivateType"> Private Types</a>
</li>
<li class="displayOptions">
<a class="current" href="/DisplayOption">Display Options</a>
</li>
</ul>
</li>
我想在悬停(或鼠标单击)时单击下拉列表中的第三个项目,或者手动使用它。
java脚本正在使用hoverIntent,这(可能)对我来说是个问题——不确定。
当我在手动运行期间使用控制台保存时,我得到:
DOMNodeRemoved DOMSubtreeModified DOMNodeInserted DOMSubtreeModified DOMNodeRemoved DOMSubtreeModified DOMNodeInserted DOMSubtreeModified DOMNodeRemoved DOMSubtreeModified
亿万次。
这是我用 ruby Watir 尝试过的编码日志:
irb(main):001:0> require 'watir'
=> true
<Watir::Browser.start("http://services.leedsgrenville.com/")
=> #<Watir::IE:0x4c618ca8 url="http://services.leedsgrenville.com/" title="Admin
istration">
<ink(:index, 1).attribute_value("/BusinessDirectoryEntry")
NoMethodError: undefined method `li' for main:Object
from (irb):3
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):004:0> browser.li(:text, 'Manage Users & groups').link(:index, 1).at>
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["li"], :text=>"Manage Users & groups"}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:135:in `document'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:31:in `document'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:136:in `each_element'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:21:in `block in each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:20:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:20:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:147:in `locate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:33:in `locate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:63:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:407:in `attribute_value'
from (irb):4
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):005:0> browser.li.flash
=> nil
irb(main):006:0> browser.li(id => "navTab02").flash
NameError: undefined local variable or method `id' for main:Object
from (irb):6
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):007:0> browser.li(id => "navTab02").flash
NameError: undefined local variable or method `id' for main:Object
from (irb):7
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):008:0> browser.li(index, 2).flash
NameError: undefined local variable or method `index' for main:Object
from (irb):8
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):009:0> browser.li(index, 2)
NameError: undefined local variable or method `index' for main:Object
from (irb):9
from C:/Ruby193/bin/irb:12:in `<main>'
<nk(:text, /Manage Content/).fire_event('onmouseover')
=> ""
<(:text, /Manage Content/).fire_event('onmouseover')
=> ""
<(:text, /Manage Content/).fire_event('onmouseover')
=> ""
irb(main):013:0> browser.link(:text, /Manage Content/).flash
=> nil
irb(main):014:0> browser.link(:text, /navTab01/).flash
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["a"], :text=>/navTab01/}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:280:in `flash'
from (irb):14
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):015:0> browser.link(:text, /navTab01/).flash
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["a"], :text=>/navTab01/}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:280:in `flash'
from (irb):15
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):016:0> browser.link(:text, /Manage Content/).flash
=> nil
irb(main):017:0> browser.link(:text, /Manage Content/).flash
=> nil
irb(main):018:0>
<(:class => 'manageContent', :text => 'Manage Content').link.click
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["li"], :class=>"manageContent", :text=>"Manage Content"}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:135:in `document'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:31:in `document'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:136:in `each_element'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:21:in `block in each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:20:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:20:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:147:in `locate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:33:in `locate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:63:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:412:in `perform_action'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:269:in `click!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:211:in `click'
from (irb):19
from C:/Ruby193/bin/irb:12:in `<main>'
<(:class => 'manageContent', :text => 'Business Directory').link.click
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["li"], :class=>"manageContent", :text=>"Business Directory"}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:135:in `document'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:31:in `document'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:136:in `each_element'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:21:in `block in each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:20:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:20:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/locator.rb:147:in `locate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:33:in `locate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:63:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:412:in `perform_action'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:269:in `click!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:211:in `click'
from (irb):20
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):021:0> browser.div(:id, "mainNav").fire_event "onmouseover"
=> ""
irb(main):022:0> browser.div(:id, "mainNav").fire_event "onmouseover"
=> ""
irb(main):023:0> browser.link(:id => "navTab01").click
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["a"], :id=>"navTab01"}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:412:in `perform_action'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:269:in `click!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:211:in `click'
from (irb):23
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):024:0> browser.link(:class => "manageUsers").click
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_
name=>["a"], :class=>"manageUsers"}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:66:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:412:in `perform_action'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:269:in `click!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:211:in `click'
from (irb):24
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):025:0> browser.div(:id, "mainNav").hover
NoMethodError: undefined method `hover' for #<Watir::Div:0x30b3610>
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-c
lassic/element.rb:431:in `method_missing'
from (irb):25
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):026:0> class Watir::Element
irb(main):027:1> def hover
irb(main):028:2> assert_exists
irb(main):029:2>
irb(main):030:2* driver.action.move_to(@element).perform
irb(main):031:2> end
irb(main):032:1> end
=> nil
<ll(:text, "Manage Content").fire_event("onmouseover")
NoMethodError: undefined method `cell' for #<Watir::IE:0x3276978>
from (irb):33
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):034:0> require 'WET'
LoadError: cannot load such file -- WET
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
from (irb):34
from C:/Ruby193/bin/irb:12:in `<main>'
实际的 Java 代码是:
$("#mainNav, #mainNavDropdown").hoverIntent(
{
interval: 200,
timeout: 1000,
over: function()
{
$(this).addClass("over");
$("#mainNavDropdown").stop(true, true).slideDown(500,
function()
{
$(this).css("height", ""); // Make sure animation didn't screw up
});
},
out: function()
{
$(this).removeClass("over");
if (!$("#mainNav, #mainNavDropdown").hasClass("over"))
$("#mainNavDropdown").stop().slideUp(500,
function()
{
$(this).css("height", ""); // Make sure animation didn't screw up
});
}
});
// Hide the menu on body click
$("body")
.click(function(evt)
{
if ($(evt.target)
.parents()
.andSelf()
.filter("#mainNav, #mainNavDropdown").length == 0)
$("#mainNavDropdown").stop().slideUp(300,
function()
{
$(this).css("height", ""); // Make sure animation didn't screw up
});
});
如果有人可以尝试帮助我,那就太棒了!