1

My list is nested under two headers and I don't know how to access them via watir since the style, display is set to "none" until a "hover" event occurs. And the class isn't defined until a hover/mousveover either.

b.link(:text, /Assessments/).fire_event('onmouseover')

will open the initial drop-down. I have no idea how to access the elements in the "sub-level"

Variations on the following are rejected by watir:

b.link(:class, "sub-level").click
b.link(:class, "sub-level").fire_event('onmouseover')
b.link(:class, "sub-level").fire_event('hover')

Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"sub-level", :tag_name=>"a"}

I've been running this through IRB for quick testing of each new line I add to my script. If this is incorrect, I would appreciate any advice.

<li class="top-level">
<a class="" href="#">
Assessments&nbsp;&nbsp;
<img id="lfArrowImg" style="border:0px;" src="https://test.com/top/images/global_nav_downArrow.gif">
</a>
  <ul style="z-index: 1045; display: none;">
  <li class="sub-level">
     <a class="">
     Assessments
     <div id="menugroup" class="dr-menu-node dr-menu-node-icon rich-menu-item-folder rich-menu-group-folder"></div>
     </a>
  <ul style="z-index: 1068; display: none;">    
  <li class="sub-level">
     <a class="" href="http://test.com/content/aa/assessment/index.xhtml">Main</a>
  </li>
  <li class="sub-level">
  <li class="sub-level">
</ul>
</li>

Thanks, Damien

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
ddavisqa
  • 85
  • 10
  • 1
    btw: congradulations for posting the 500th Stack Overflow item with a 'watir' tag on it. (no, you don't win anything, other than I hope a good answer to your question. – Chuck van der Linden Jan 10 '12 at 06:12
  • you hope? as long as you answered it, the good part is in the bag. – Dave McNulla Jan 10 '12 at 15:32
  • heh not counting that chicken till I see a big green checkmark indicating an accepted answer. I'm not always right, and I'm always learning more (often as a result of researching answers to questions). Although my wife found an expression the other day that is almost perfect.. "often in error, never in doubt" LOL – Chuck van der Linden Jan 10 '12 at 16:38
  • No luck, gentlemen. I can fire off the Top-level Assessment link which will display a list. Trying to access anything on the list is a problem. And 'li' is expecting a hash. b.li(:class, 'sub-level', :text, 'Assessments').link.click ArgumentError: expected Hash or (:how, 'what'), got [:class, "sub-level", :text, "Assessments"] from C:/Ruby/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.4.1/lib/watir-webdriver/container.rb :26:in `extract_selector' from C:/Ruby/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.4.1/lib/watir-webdriver/elements/generated.rb:1769:in `li' – ddavisqa Jan 12 '12 at 18:41
  • You are not expressing the hash correctly. Compare what you wrote above to what I gave in my answer. You have put commas between the name and the value. You need to separate the name and value with `=>` and then put commas between the `name => value` groups. `b.li(:class => 'sub-level', :text => 'Assessments').link.click` – Chuck van der Linden Jan 14 '12 at 00:59

1 Answers1

2

The error is correct since you have no link tag in that code with a class of sub-level. The things with that class are li (List Item) elements which contain link elements (aka 'anchor' hence the a tag)

Try something like this (depending on which link you want to click)

browser.li(:class => 'sub-level', :text => 'Assessments').link.click
browser.li(:class => 'sub-level', :text => 'Main').link.click

For more on ways to identify elements, especially if they do not have a handy ID, Class etc, see the answers to this SO question: How to get index of parent element using Watir Webdriver? and the answers (all three) to this question also: Accessing an element with no attributes in Watir

Community
  • 1
  • 1
Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43